-
Notifications
You must be signed in to change notification settings - Fork 9
oidc dynamic credential support #177
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
5 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| # HYOK OIDC configurations | ||
|
|
||
| Hold-Your-Own-Key (HYOK) OIDC configurations let HCP Terraform federate to | ||
| AWS, Azure, GCP, or Vault without storing a static credential. pyTFE exposes | ||
| one service per provider: | ||
|
|
||
| - `client.aws_oidc_configurations` | ||
| - `client.azure_oidc_configurations` | ||
| - `client.gcp_oidc_configurations` | ||
| - `client.vault_oidc_configurations` | ||
|
|
||
| Upstream docs: | ||
|
|
||
| - AWS: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/hold-your-own-key/oidc-configurations/aws | ||
| - Azure: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/hold-your-own-key/oidc-configurations/azure | ||
| - GCP: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/hold-your-own-key/oidc-configurations/gcp | ||
| - Vault: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/hold-your-own-key/oidc-configurations/vault | ||
|
|
||
| Example: [oidc_configurations.py](../../examples/oidc_configurations.py) | ||
|
|
||
| ## What these resources do (and do not) manage | ||
|
|
||
| These services manage the **HCP Terraform-side configuration record** only. | ||
| They do **not** provision the cloud-side trust resources: | ||
|
|
||
| | The SDK creates | You still need to provision separately | | ||
| |---|---| | ||
| | AWS OIDC configuration record (role ARN, organization) | IAM OIDC provider for HCP Terraform; IAM role and trust policy | | ||
| | Azure OIDC configuration record (client/subscription/tenant IDs) | Azure AD app registration; service principal; federated credential | | ||
| | GCP OIDC configuration record (SA email, project number, workload provider name) | Workload Identity Federation pool/provider; service account IAM bindings | | ||
| | Vault OIDC configuration record (address, role, auth path, namespace) | Vault JWT auth method; role; policies | | ||
|
|
||
| These configurations require **HYOK / Premium entitlement** on the | ||
| organization. Calls against a non-HYOK org return `404` or `403`. | ||
|
|
||
| For per-workspace dynamic credentials (not HYOK), see | ||
| [scenarios/oidc-dynamic-credentials.md](../scenarios/oidc-dynamic-credentials.md) | ||
| — that's still done via `client.variables` or `client.variable_sets`. | ||
|
|
||
| ## Shared HTTP shape | ||
|
|
||
| All four providers hit the same endpoints; the provider is determined by the | ||
| JSON:API `data.type` string in the body, not the URL: | ||
|
|
||
| | Operation | Method | Path | | ||
| |---|---|---| | ||
| | Create | `POST` | `/api/v2/organizations/{org}/oidc-configurations` | | ||
| | Read | `GET` | `/api/v2/oidc-configurations/{id}` | | ||
| | Update | `PATCH` | `/api/v2/oidc-configurations/{id}` | | ||
| | Delete | `DELETE` | `/api/v2/oidc-configurations/{id}` | | ||
|
|
||
| `data.type` values per provider: | ||
|
|
||
| | Provider | `data.type` | | ||
| |---|---| | ||
| | AWS | `aws-oidc-configurations` | | ||
| | Azure | `azure-oidc-configurations` | | ||
| | GCP | `gcp-oidc-configurations` | | ||
| | Vault | `vault-oidc-configurations` | | ||
|
|
||
| ## AWS | ||
|
|
||
| | Method | Purpose | | ||
| |---|---| | ||
| | `client.aws_oidc_configurations.create(organization, options)` | Register an IAM role ARN for OIDC federation. | | ||
| | `client.aws_oidc_configurations.read(oidc_configuration_id)` | Read configuration. | | ||
| | `client.aws_oidc_configurations.update(oidc_configuration_id, options)` | Update role ARN. | | ||
| | `client.aws_oidc_configurations.delete(oidc_configuration_id)` | Delete the configuration. | | ||
|
|
||
| ```python | ||
| from pytfe import TFEClient | ||
| from pytfe.models import AWSOIDCConfigurationCreateOptions | ||
|
|
||
| client = TFEClient() | ||
|
|
||
| aws = client.aws_oidc_configurations.create( | ||
| "my-organization", | ||
| AWSOIDCConfigurationCreateOptions( | ||
| role_arn="arn:aws:iam::123456789012:role/hcp-terraform", | ||
| ), | ||
| ) | ||
| print(aws.id, aws.role_arn) | ||
| ``` | ||
|
|
||
| ## Azure | ||
|
|
||
| | Method | Purpose | | ||
| |---|---| | ||
| | `client.azure_oidc_configurations.create(organization, options)` | Register Azure AD app/subscription/tenant. | | ||
| | `client.azure_oidc_configurations.read(oidc_configuration_id)` | Read configuration. | | ||
| | `client.azure_oidc_configurations.update(oidc_configuration_id, options)` | Update one or more IDs. | | ||
| | `client.azure_oidc_configurations.delete(oidc_configuration_id)` | Delete the configuration. | | ||
|
|
||
| ```python | ||
| from pytfe.models import AzureOIDCConfigurationCreateOptions | ||
|
|
||
| azure = client.azure_oidc_configurations.create( | ||
| "my-organization", | ||
| AzureOIDCConfigurationCreateOptions( | ||
| client_id="00000000-0000-0000-0000-000000000000", | ||
| subscription_id="11111111-1111-1111-1111-111111111111", | ||
| tenant_id="22222222-2222-2222-2222-222222222222", | ||
| ), | ||
| ) | ||
| ``` | ||
|
|
||
| All three of `client_id`, `subscription_id`, `tenant_id` are required on | ||
| create. Update accepts any subset; unset fields are not touched. | ||
|
|
||
| ## GCP | ||
|
|
||
| | Method | Purpose | | ||
| |---|---| | ||
| | `client.gcp_oidc_configurations.create(organization, options)` | Register the service account + workload provider. | | ||
| | `client.gcp_oidc_configurations.read(oidc_configuration_id)` | Read configuration. | | ||
| | `client.gcp_oidc_configurations.update(oidc_configuration_id, options)` | Update SA email, project number, or provider name. | | ||
| | `client.gcp_oidc_configurations.delete(oidc_configuration_id)` | Delete the configuration. | | ||
|
|
||
| ```python | ||
| from pytfe.models import GCPOIDCConfigurationCreateOptions | ||
|
|
||
| gcp = client.gcp_oidc_configurations.create( | ||
| "my-organization", | ||
| GCPOIDCConfigurationCreateOptions( | ||
| service_account_email="tfc@my-project.iam.gserviceaccount.com", | ||
| project_number="123456789012", | ||
| workload_provider_name=( | ||
| "projects/123456789012/locations/global/" | ||
| "workloadIdentityPools/hcp/providers/hcp-terraform" | ||
| ), | ||
| ), | ||
| ) | ||
| ``` | ||
|
|
||
| ## Vault | ||
|
|
||
| Vault has the most non-obvious field mappings — the Python names differ from | ||
| the wire names: | ||
|
|
||
| | Python field | Wire name | Required on create | | ||
| |---|---|---| | ||
| | `address` | `address` | yes | | ||
| | `role_name` | `role` | yes | | ||
| | `namespace` | `namespace` | no | | ||
| | `jwt_auth_path` | `auth-path` | no | | ||
| | `tls_ca_certificate` | `encoded-cacert` | no | | ||
|
|
||
| | Method | Purpose | | ||
| |---|---| | ||
| | `client.vault_oidc_configurations.create(organization, options)` | Register Vault address + role. | | ||
| | `client.vault_oidc_configurations.read(oidc_configuration_id)` | Read configuration. | | ||
| | `client.vault_oidc_configurations.update(oidc_configuration_id, options)` | Update any field. | | ||
| | `client.vault_oidc_configurations.delete(oidc_configuration_id)` | Delete the configuration. | | ||
|
|
||
| ```python | ||
| from pytfe.models import VaultOIDCConfigurationCreateOptions | ||
|
|
||
| vault = client.vault_oidc_configurations.create( | ||
| "my-organization", | ||
| VaultOIDCConfigurationCreateOptions( | ||
| address="https://vault.example.com", | ||
| role_name="hcp-terraform", | ||
| namespace="admin", | ||
| jwt_auth_path="jwt", | ||
| tls_ca_certificate="-----BEGIN CERTIFICATE-----\n...", | ||
| ), | ||
| ) | ||
| ``` | ||
|
|
||
| ## Token requirements | ||
|
|
||
| Write endpoints require an organization, owner, or HYOK admin token. See | ||
| HCP's HYOK docs for the exact permission model. Read endpoints follow the | ||
| same permission rules as other organization-scoped reads. | ||
|
|
||
| ## Operational notes | ||
|
|
||
| - **Update is partial.** Pass only the fields you want to change. Unset | ||
| fields are not sent on the wire, so the server keeps the existing value. | ||
| - **Plan rotations carefully.** Updating the IAM role ARN or service account | ||
| email mid-flight will interrupt any in-progress runs that rely on the | ||
| federated credential. | ||
| - **Configurations are per-organization.** If you have multiple HCP | ||
| Terraform organizations sharing a cloud account, each needs its own | ||
| configuration record (and a distinct trust policy/federated credential on | ||
| the cloud side). | ||
| - **HYOK is required.** Without the entitlement these endpoints return | ||
| `404`. The SDK will surface that as `pytfe.errors.NotFound`. | ||
Oops, something went wrong.
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.
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.
This example passes a raw PEM block into the field that is serialized as
encoded-cacert, but the Vault OIDC API expects that attribute to be a base64-encoded CA certificate. Users copying this for self-hosted Vault with a custom CA will send an invalid value and get a server-side validation error; the example should either base64-encode the PEM first or show an already encoded value.Useful? React with 👍 / 👎.