Manage Ory Network configuration in git
This guide will walk you through the process of managing your Ory Network configuration in Git using GitHub Actions. By following these steps, you'll be able to track changes, review, and approve them through pull requests, and automatically update the configuration upon merge.
This guide uses the GitHub Actions to update the configuration and manage changes through pull requests. You can adapt this to GitLab CI, TravisCI, CircleCI, and other CI/CD systems.
Ory Network configuration
Ory Identities configuration
First, pull the current configuration from your Ory Network project. You can also automate this with a GitHub Action, but in this
case, you just need it once. You can find the workspace-id
and project-id
in the Ory Network dashboard or by using ory list workspaces
and ory list projects --workspace <workspace_id>
.
ory get identity-config --workspace "<workspace-id>" --project "<project-id>" --format json-pretty > identity-config.json
Commit the configuration to git and push it to your repository.
Now create a GitHub Action that will update the configuration when a pull request is merged.
Create a new file .github/workflows/ory-cli.yml
. Add the following content to it:
name: Update Ory Network Config
env:
ORY_PROJECT_ID: "<project-id>"
ORY_WORKSPACE_ID: "<workspace-id>"
ORY_WORKSPACE_API_KEY: ${{ secrets.ORY_WORKSPACE_API_KEY }}
on:
push:
branches:
- master
jobs:
run-ory-cli:
runs-on: ubuntu-latest
container: oryd/ory:v1
steps:
- name: checkout
uses: actions/checkout@v3
- name: Push changes to Ory Network
run: ory update identity-config --file identity-config.json
For the GitHub Action to authenticate with Ory Network, you need to add the ORY_WORKSPACE_API_KEY secret to your repository. You can configure secrets in the repository's settings.
Now you can make changes to the configuration in git and create pull requests to review and approve the changes. When the pull request is merged, the configuration will be updated automatically. You can also use this to roll back changes via the git history.
Ory OAuth2 & OpenID Connect configuration
The above approach works in the same way for other Ory Network configuration commands. For example, you can use the same approach to manage the Ory OAuth2 & OpenID Connect configuration in git. First, pull the current configuration from your Ory Network project:
ory get oauth2-config "$PROJECT_ID" --format json-pretty > oauth2-config-"$PROJECT_ID".json
Switch out the command in the GitHub Action:
- update identity-config "$PROJECT_ID" --file identity-config-"$PROJECT_ID".json
+ update oauth2-config "$PROJECT_ID" --file oauth2-config-"$PROJECT_ID".json
Ory Permissions configuration and Ory Permission Language
You can use the same approach to manage the Ory Permissions configuration in git. First, pull the current configuration from your Ory Network project:
ory get permission-config "$PROJECT_ID" --format json-pretty > permission-config-"$PROJECT_ID".json
Add the update command for Ory Permissions configuration to the GitHub Action:
update permission-config "$PROJECT_ID" --file permission-config-"$PROJECT_ID".json
or for the Ory Permission Language configuration:
update opl --project "$PROJECT_ID" --file opl-"$PROJECT_ID".ts
OpenID Connect Claims and Ory Actions payload
Ory uses JSONNet snippets for mapping OIDC provider claims to Ory Network identities and for configuring the payload of Ory Actions webhooks. You can save and version these snippets in git. You have several options for managing JSONNet snippets in git. Here's an example of how you can organize them:
mkdir oidc-mapping
touch oidc-mapping/google.jsonnet
# add the mappings for OIDC providers you use
mkdir actions-payload
touch actions-payload/registration.jsonnet
# add the JSONNet payloads for Ory Actions you use
When you make changes, convert the new OIDC mapping or Ory Actions payload to base64 and add it to the config file. You can use the following command to convert a file to base64 and copy it to the clipboard:
base64 < oidc-mapping/google.jsonnet | pbcopy
Now add the base64 encoded string to your configuration, this is how it looks with Ory Actions webhooks:
//...
"hooks": [
{
"config": {
"body": "base64://PASTE_BASE64_STRING_HERE",
//...
}
}
]
//...
This is how it looks with OIDC mappings:
//...
"oidc": {
//...
{
//...
"mapper_url": "base64://PASTE_BASE64_STRING_HERE",
//...
}
},
//...
When you update the configuration, Ory Network will automatically decode the base64 string and save the JSONNet snippet in the Ory Network backend.
Identity Schema
It can also be useful to version the Identity Schema. This is the schema that's used to validate the identity data when new identities are created. Most of the time this won't change, but if you use custom Identity Schemas it can help to keep track of changes. You can copy the Identity Schema directly from the Ory Network console or get it from the config file you pulled earlier.
For example:
//...
# This is the default schema that's used for new identities
"default_schema_id": "preset://email",
# These are custom schemas that are available on your Ory Network project
"schemas": [
{
"id": "7d1cf71e-57ae-40be-bddf-1f4c323e2349",
"url": "https://storage.googleapis.com/bac-gcs-production/something.schema.json"
},
],
//...
You can now save the default Identity Schema and custom Identity Schemas in git. When you make changes, convert the new Identity Schema to base64 and update it in the config file. You can only update existing identity schemas, to create a new one use the Ory Console. Use the following command to convert a file to base64 and copy it to the clipboard:
base64 < identity-schema.json | pbcopy
Now add the base64 encoded string to your configuration:
//...
"schemas": [
{
"id": "7d1cf71e-57ae-40be-bddf-1f4c323e2349",
"url": "base64://PASTE_BASE64_STRING_HERE"
},
],
//...
When you update the configuration, Ory Network will automatically decode the base64 string and save the updated Identity Schema in the Ory Network backend.
Email Templates
You can also version and track email templates in the same way. One option is to create a folder in your repository for email templates and add the .html templates there. As with the other configurations you have to convert it into base64 and add it to the config file, whenever you make changes to the template.
Read the Custom email templates with Ory blog post to learn more about email template configuration via the Ory CLI.