-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add docs for database auto user provisioning #26987
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1fcb3d7
Add docs for database auto user provisioning
r0mant b281b54
Address feedback
r0mant 9ad6ae7
Fix
r0mant 0b5e9d2
More lint fixes
r0mant 149b455
Fix
r0mant 10a4cb1
Apply suggestions from code review
r0mant 8567e82
Merge branch 'master' into roman/docs/dbuser
r0mant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,135 +1,13 @@ | ||
| --- | ||
| title: Database Role-Based Access Controls | ||
| description: Role-based access control (RBAC) for Teleport database access. | ||
| title: Database Access Control Guides | ||
| description: Role-based access control guides for Teleport database access. | ||
| --- | ||
|
|
||
| Role-based access control (or RBAC, for short) allows administrators to set up | ||
| granular access policies for databases connected to Teleport. | ||
| These guides cover configuring access control policies for database users. | ||
|
|
||
| An example of a policy could be, *"database administrators have access to | ||
| everything, QA team and engineers have full access to staging databases, and | ||
| engineers can gain temporary access to the production database in case of | ||
| emergency"*. | ||
| Read the [RBAC](./rbac/configuring-access.mdx) guide to get a general understanding | ||
| of how to configure Teleport roles to grant or deny access to your database users. | ||
|
|
||
| For a more general description of Teleport roles and examples see [RBAC](../access-controls/introduction.mdx), as | ||
| this section focuses on configuring RBAC for database access. | ||
|
|
||
| ## Role configuration | ||
|
|
||
| Teleport's "role" resource provides the following instruments for restricting | ||
| database access: | ||
|
|
||
| ```yaml | ||
| kind: role | ||
| version: v5 | ||
| metadata: | ||
| name: developer | ||
| spec: | ||
| allow: | ||
| # Label selectors for database instances this role has access to. | ||
| # | ||
| # These will be matched against the static/dynamic labels set on the | ||
| # database service. | ||
| db_labels: | ||
| environment: ["dev", "stage"] | ||
|
|
||
| # Database account names this role can connect as. | ||
| db_users: ["viewer", "editor"] | ||
|
|
||
| # Database names this role will be able to connect to. | ||
| # | ||
| # Note, this is not the same as the "name" field in "db_service", this is | ||
| # the database names within a particular database instance. | ||
| # | ||
| # Also note, this setting has effect only for PostgreSQL. It does not | ||
| # currently have any effect on MySQL databases/schemas. | ||
| db_names: ["main", "metrics", "postgres"] | ||
| ``` | ||
|
|
||
| It is possible to use wildcards to match any database names/users. | ||
|
|
||
| For example, the following role permits access to any database/user within a | ||
| production database except for the internal "postgres" database/user: | ||
|
|
||
| ```yaml | ||
| kind: role | ||
| version: v5 | ||
| metadata: | ||
| name: developer | ||
| spec: | ||
| allow: | ||
| db_labels: | ||
| environment: ["prod"] | ||
| db_users: ["*"] | ||
| db_names: ["*"] | ||
| deny: | ||
| db_users: ["postgres"] | ||
| db_names: ["postgres"] | ||
| ``` | ||
|
|
||
| <Admonition | ||
| type="note" | ||
| title="Deny Rules" | ||
| > | ||
| Deny rules will match greedily. In the example above, a database connection | ||
| attempting to use "postgres" database account (regardless of database instance | ||
| or database name) or "postgres" database name (regardless of database instance | ||
| or database account) will be rejected. | ||
| </Admonition> | ||
|
|
||
| ## Database names | ||
|
|
||
| There's a distinction in how different database servers handle logical databases | ||
| which leads to a difference in how `db_names` role field is applied to a connection | ||
| attempt. | ||
|
|
||
| PostgreSQL supports multiple logical databases, and each logical database can | ||
| contain multiple schemas. In order to change to a different database, a user | ||
| disconnects from the current one and establishes a new connection. During a | ||
| PostgreSQL connection attempt, `db_names` field is checked against the name | ||
| of the logical database that the user is connecting to. | ||
|
|
||
| In MySQL a logical "database" and a "schema" are synonyms for each other, and | ||
| the scope of permissions a user has once connected is determined by the permission | ||
| grants set on the account within the database. As such, `db_names` role field | ||
| is not currently enforced on MySQL connection attempts. | ||
|
|
||
| ## Template variables | ||
|
|
||
| Similar to other role fields, `db_*` fields support templating variables. | ||
|
|
||
| The `{{external.xyz}}` variables are replaced with values from external [SSO](../access-controls/sso.mdx) | ||
| providers. For OIDC, they will be expanded with a value of an "xyz" claim; for | ||
| SAML — with an "xyz" assertion value. | ||
|
|
||
| For example, here is what a role may look like if you want to assign allowed | ||
| database names from the user's Okta `databases` assertion: | ||
|
|
||
| ```yaml | ||
| spec: | ||
| allow: | ||
| db_names: ["{{external.databases}}"] | ||
| ``` | ||
|
|
||
| The `{{internal.db_users}}` and `{{internal.db_names}}` variables permit sharing | ||
| allowed database accounts and names with remote clusters. They will be replaced | ||
| with the respective properties of a remote user connecting from a root cluster. | ||
|
|
||
| For example, suppose a user in the root cluster has the following role: | ||
|
|
||
| ```yaml | ||
| spec: | ||
| allow: | ||
| db_users: ["postgres"] | ||
| db_names: ["postgres"] | ||
| ``` | ||
|
|
||
| The role on the leaf cluster can be set up to use the user's allowed database | ||
| accounts and names: | ||
|
|
||
| ```yaml | ||
| spec: | ||
| allow: | ||
| db_users: ["{{internal.db_users}}"] | ||
| db_names: ["{{internal.db_names}}"] | ||
| ``` | ||
| The [Automatic User Provisioning](./rbac/configuring-auto-user-provisioning.mdx) | ||
| guide explains how to get Teleport to create accounts for your PostgreSQL users | ||
| on-demand. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| --- | ||
| title: Database Access RBAC | ||
| description: Role-based access control (RBAC) for Teleport database access. | ||
| --- | ||
|
|
||
| Role-based access control (or RBAC, for short) allows administrators to set up | ||
| granular access policies for databases connected to Teleport. | ||
|
|
||
| An example of a policy could be, *"database administrators have access to | ||
| everything, QA team and engineers have full access to staging databases, and | ||
| engineers can gain temporary access to the production database in case of | ||
| emergency"*. | ||
|
|
||
| For a more general description of Teleport roles and examples see [RBAC](../../access-controls/introduction.mdx), as | ||
| this section focuses on configuring RBAC for database access. | ||
|
|
||
| ## Role configuration | ||
|
|
||
| Teleport's "role" resource provides the following instruments for restricting | ||
| database access: | ||
|
|
||
| ```yaml | ||
| kind: role | ||
| version: v5 | ||
| metadata: | ||
| name: developer | ||
| spec: | ||
| allow: | ||
| # Label selectors for database instances this role has access to. | ||
| # | ||
| # These will be matched against the static/dynamic labels set on the | ||
| # database service. | ||
| db_labels: | ||
| environment: ["dev", "stage"] | ||
|
|
||
| # Database account names this role can connect as. | ||
| db_users: ["viewer", "editor"] | ||
|
|
||
| # Database names this role will be able to connect to. | ||
| # | ||
| # Note, this is not the same as the "name" field in "db_service", this is | ||
| # the database names within a particular database instance. | ||
| # | ||
| # Also note, this setting has effect only for PostgreSQL. It does not | ||
| # currently have any effect on MySQL databases/schemas. | ||
| db_names: ["main", "metrics", "postgres"] | ||
| ``` | ||
|
|
||
| It is possible to use wildcards to match any database names/users. | ||
|
|
||
| For example, the following role permits access to any database/user within a | ||
| production database except for the internal "postgres" database/user: | ||
|
|
||
| ```yaml | ||
| kind: role | ||
| version: v5 | ||
| metadata: | ||
| name: developer | ||
| spec: | ||
| allow: | ||
| db_labels: | ||
| environment: ["prod"] | ||
| db_users: ["*"] | ||
| db_names: ["*"] | ||
| deny: | ||
| db_users: ["postgres"] | ||
| db_names: ["postgres"] | ||
| ``` | ||
|
|
||
| <Admonition | ||
| type="note" | ||
| title="Deny Rules" | ||
| > | ||
| Deny rules will match greedily. In the example above, a database connection | ||
| attempting to use "postgres" database account (regardless of database instance | ||
| or database name) or "postgres" database name (regardless of database instance | ||
| or database account) will be rejected. | ||
| </Admonition> | ||
|
|
||
| ## Database names | ||
|
|
||
| There's a distinction in how different database servers handle logical databases | ||
| which leads to a difference in how `db_names` role field is applied to a connection | ||
| attempt. | ||
|
|
||
| PostgreSQL supports multiple logical databases, and each logical database can | ||
| contain multiple schemas. In order to change to a different database, a user | ||
| disconnects from the current one and establishes a new connection. During a | ||
| PostgreSQL connection attempt, `db_names` field is checked against the name | ||
| of the logical database that the user is connecting to. | ||
|
|
||
| In MySQL a logical "database" and a "schema" are synonyms for each other, and | ||
| the scope of permissions a user has once connected is determined by the permission | ||
| grants set on the account within the database. As such, `db_names` role field | ||
| is not currently enforced on MySQL connection attempts. | ||
|
|
||
| ## Template variables | ||
|
|
||
| Similar to other role fields, `db_*` fields support templating variables. | ||
|
|
||
| The `{{external.xyz}}` variables are replaced with values from external [SSO](../../access-controls/sso.mdx) | ||
| providers. For OIDC, they will be expanded with a value of an "xyz" claim; for | ||
| SAML — with an "xyz" assertion value. | ||
|
|
||
| For example, here is what a role may look like if you want to assign allowed | ||
| database names from the user's Okta `databases` assertion: | ||
|
|
||
| ```yaml | ||
| spec: | ||
| allow: | ||
| db_names: ["{{external.databases}}"] | ||
| ``` | ||
|
|
||
| The `{{internal.db_users}}` and `{{internal.db_names}}` variables permit sharing | ||
| allowed database accounts and names with remote clusters. They will be replaced | ||
| with the respective properties of a remote user connecting from a root cluster. | ||
|
|
||
| For example, suppose a user in the root cluster has the following role: | ||
|
|
||
| ```yaml | ||
| spec: | ||
| allow: | ||
| db_users: ["postgres"] | ||
| db_names: ["postgres"] | ||
| ``` | ||
|
|
||
| The role on the leaf cluster can be set up to use the user's allowed database | ||
| accounts and names: | ||
|
|
||
| ```yaml | ||
| spec: | ||
| allow: | ||
| db_users: ["{{internal.db_users}}"] | ||
| db_names: ["{{internal.db_names}}"] | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.