-
Notifications
You must be signed in to change notification settings - Fork 463
feat: Docs for client secret rotation #2424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
20e4ba2
092745e
cf5d2be
018837b
8c18152
29299a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -131,6 +131,137 @@ See [API documentation](../../reference/api#tag/oAuth2/operation/patchOAuth2Clie | |||||
| </Tabs> | ||||||
| ```` | ||||||
|
|
||||||
| ## Rotate OAuth2 client secret | ||||||
|
|
||||||
| OAuth2 client secret rotation allows you to change a client's secret without downtime. When you rotate a secret, the old secret | ||||||
| remains valid until you explicitly clean it up, allowing you to update all services using the client credentials without service | ||||||
| interruption. | ||||||
|
|
||||||
| ##### How secret rotation works | ||||||
|
|
||||||
| 1. Rotate the secret: Generate a new secret for the client | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 2. Both secrets work: Old and new secrets both authenticate until cleanup | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| 3. Update services: Update your applications to use the new secret | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 4. Cleanup: Manually remove old rotated secrets once all services are updated | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| ##### Rotate client secret | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| To rotate an OAuth2 client secret, use the following methods: | ||||||
|
|
||||||
| ````mdx-code-block | ||||||
| <Tabs> | ||||||
| <TabItem value="rest" label="REST API"> | ||||||
|
|
||||||
| ```bash | ||||||
| curl -X POST https://{project.slug}.projects.oryapis.com/admin/clients/{client-id}/secret/rotate \ | ||||||
| -H "Authorization: Bearer ory_pat_..." | ||||||
| ``` | ||||||
|
|
||||||
| The response includes the new `client_secret`. Save this value immediately - it will not be shown again. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where should this be saved? Is there a secure location it should be saved to? |
||||||
|
|
||||||
| See [API documentation](../../reference/api#tag/oAuth2/operation/rotateOAuth2ClientSecret). | ||||||
|
|
||||||
| </TabItem> | ||||||
| <TabItem value="sdk" label="Ory SDK"> | ||||||
|
|
||||||
| ```typescript | ||||||
| import { Configuration, OAuth2Api } from "@ory/client" | ||||||
|
|
||||||
| const ory = new OAuth2Api( | ||||||
| new Configuration({ | ||||||
| basePath: `https://${projectSlug}.projects.oryapis.com`, | ||||||
| accessToken: "ory_pat_..." | ||||||
| }) | ||||||
| ) | ||||||
|
|
||||||
| const { data: client } = await ory.rotateOAuth2ClientSecret({ | ||||||
| id: clientId | ||||||
| }) | ||||||
|
|
||||||
| // Save the new client_secret immediately | ||||||
| console.log("New secret:", client.client_secret) | ||||||
| ``` | ||||||
|
|
||||||
| </TabItem> | ||||||
| </Tabs> | ||||||
| ```` | ||||||
|
|
||||||
| ##### Clear rotated secrets | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| Once all services have been updated to use the new secret, you can remove the old rotated secrets to revoke access using the old | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| credentials: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| ````mdx-code-block | ||||||
| <Tabs> | ||||||
| <TabItem value="rest" label="REST API"> | ||||||
|
|
||||||
| ```bash | ||||||
| curl -X DELETE https://{project.slug}.projects.oryapis.com/admin/clients/{client-id}/secret/rotate \ | ||||||
| -H "Authorization: Bearer ory_pat_..." | ||||||
| ``` | ||||||
|
|
||||||
| After cleanup, only the current secret will be valid. Old secrets will no longer authenticate. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| See [API documentation](../../reference/api#tag/oAuth2/operation/deleteRotatedOAuth2ClientSecrets). | ||||||
|
|
||||||
| </TabItem> | ||||||
| <TabItem value="sdk" label="Ory SDK"> | ||||||
|
|
||||||
| ```typescript | ||||||
| await ory.deleteRotatedOAuth2ClientSecrets({ | ||||||
| id: clientId | ||||||
| }) | ||||||
|
|
||||||
| // Old secrets are now revoked | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ``` | ||||||
|
|
||||||
| </TabItem> | ||||||
| </Tabs> | ||||||
| ```` | ||||||
|
|
||||||
| ##### Secret rotation workflow example | ||||||
|
|
||||||
| Here's a complete workflow for rotating a client secret: | ||||||
|
|
||||||
| ```bash | ||||||
| # 1. Get current client | ||||||
| CLIENT_ID="your-client-id" | ||||||
|
|
||||||
| # 2. Rotate the secret | ||||||
| NEW_SECRET=$(curl -X POST "https://{project.slug}.projects.oryapis.com/admin/clients/$CLIENT_ID/secret/rotate" \ | ||||||
| -H "Authorization: Bearer ory_pat_..." | jq -r '.client_secret') | ||||||
|
|
||||||
| echo "New secret: $NEW_SECRET" | ||||||
|
|
||||||
| # 3. Update your applications with the new secret | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| # (Both old and new secrets work during this period) | ||||||
|
|
||||||
| # 4. Verify the new secret works | ||||||
| curl -X POST "https://{project.slug}.projects.oryapis.com/oauth2/token" \ | ||||||
| -u "$CLIENT_ID:$NEW_SECRET" \ | ||||||
| -d "grant_type=client_credentials" | ||||||
|
|
||||||
| # 5. Once all services are updated, clean up old secrets | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| curl -X DELETE "https://{project.slug}.projects.oryapis.com/admin/clients/$CLIENT_ID/secret/rotate" \ | ||||||
| -H "Authorization: Bearer ory_pat_..." | ||||||
|
|
||||||
| # Old secret is now revoked | ||||||
| ``` | ||||||
|
|
||||||
| :::tip Zero-downtime credential rotation | ||||||
|
|
||||||
| Secret rotation enables zero-downtime credential updates. Both the old and new secrets remain valid until you manually clean up | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| the rotated secrets, allowing you to update all your services without service interruption. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| ::: | ||||||
|
|
||||||
| :::warning Security best practice | ||||||
|
|
||||||
| Rotated secrets remain valid indefinitely until you explicitly clean them up. Always remove old rotated secrets once your | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "secrets remain valid indefinitely" Are you sure? Don't they have a validity date? Deepak just added this feature: "The SAML connection includes a |
||||||
| migration is complete to ensure that compromised credentials cannot be used. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| ::: | ||||||
|
|
||||||
| ## Delete OAuth2 client | ||||||
|
|
||||||
| To delete an existing OAuth2 client, use the following methods: | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.