-
Notifications
You must be signed in to change notification settings - Fork 210
doc: Migration guide to move from API Keys (PAKs) to Service Accounts #4047
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
Changes from 7 commits
6673a65
abbcbc5
d861ec5
f71aec5
94d9269
a0d4586
785a98e
dc6053d
5939987
647528f
2d95fdd
74cc59f
766060a
9a96afa
e9f3c55
52d2486
dd6acfc
0fdf9ee
23927a3
8819abd
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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,276 @@ | ||||||
| --- | ||||||
| page_title: "Migration Guide: Programmatic API Keys (PAKs) to Service Accounts (SAs)" | ||||||
| --- | ||||||
|
|
||||||
| # Migration Guide: Programmatic API Keys (PAKs) to Service Accounts (SAs) | ||||||
|
|
||||||
| ## Overview | ||||||
|
|
||||||
| This guide explains how to migrate from Programmatic API Key (PAK) resources to Service Account (SA) resources. | ||||||
|
|
||||||
| **Note:** Migration to Service Accounts is **not required**. If you are currently using API Key resources, you may continue to do so. This guide is for users who wish to adopt Service Accounts for greater security or best practices, but existing PAK configurations will continue to work and be supported. | ||||||
|
||||||
| **Note:** Migration to Service Accounts is **not required**. If you are currently using API Key resources, you may continue to do so. This guide is for users who wish to adopt Service Accounts for greater security or best practices, but existing PAK configurations will continue to work and be supported. | |
| **Note:** Migration to Service Accounts is recommended but **not required**. If you are currently using API Key resources, you may continue to do so. This guide is for users who wish to adopt Service Accounts for greater security or best practices, but existing PAK configurations will continue to work and be supported. |
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.
updated! thank you!
Outdated
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.
Just a suggestion for smoother reading:
| - **Secrets handling** - Managing Service Accounts with Terraform will expose sensitive organizational secrets in Terraform's state. We suggest following [Terraform's best practices](https://developer.hashicorp.com/terraform/language/state/sensitive-data). | |
| - Managing Service Accounts with Terraform **exposes sensitive organizational secrets** in Terraform's state. We suggest following [Terraform's best practices](https://developer.hashicorp.com/terraform/language/state/sensitive-data). |
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.
updated! thank you!
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.
I think you missed the removal of **Secrets handling** - .
Can you also update this in the secrets rotation guide to keep consistency? Ty!
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.
updated. thank you! will update that guide in the next doc PR (soon) as I would need to rebase this one and it is not worth the effort.
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.
[nit] Would it make sense to use L3 headings for everything within this section? (Right sub headings are all L2)
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.
updated! thank you!
manupedrozo marked this conversation as resolved.
Show resolved
Hide resolved
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.
I think the statement "allows both authentication methods to work simultaneously" is not true, both SA and PAK exist simultaneously, but are not used simultaneously.
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.
I was thinking on the case of using SA/PAKs as the authentication method for the MongoDB Atlas Terraform Provider, but in the cases of other applications/tools, the statement can be true. Feel free to ignore the previous comment
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.
should we explain how that would look like in the case of switching the auth method of the TF provider from PAK to SA? something similar to https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/provider-configuration#programmatic-access-key warning block where we say Update your provider attributes or environment variables to use SA credentials instead of PAK credentials, then run terraform plan to verify everything works correctly.
I say this because the guide is generic in terms of the application that uses the PAK/SA, but I think the main use case we want to enable is the TF provider authentication
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.
A previous iteration mentioned this. I suggested to remove it to avoid confusion and mention only "your applications".
For example: If the user were to change the provider credentials in this same config, they would not have permissions to re-apply as the SA has only ORG_MEMBER role.
I think it makes sense for the credentials used for provider authentication in a particular configuration to be managed outside of that same configuration.
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.
I think we should cover the end to end case of using the new SA resource sand switching from PAK to SA as the auth method, since it's the main problem we are trying to solve by implementing these resources in TF
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.
I am on board on including a link to the SA authentication registry page to reference how it is used but I would be careful to add it as a step here given the previous comment:
I think it makes sense for the credentials used for provider authentication in a particular configuration to be managed outside of that same configuration.
Do we know of PAK users authenticating with a PAK that is managed within the same configuration? I don't think we should be recommending this approach (can lock yourself out).
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.
I am not saying to recommend the approach of using PAKs created in a configuration as the auth mechanism within the same configuration, but I would like to have in this guide the case of switching from PAK to SA as the auth mechanism of the TF provider, which is the main use case we want to enable, even if the SA/PAK is created in one configuration and used as auth in another. Hope that makes sense
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.
Yes that makes sense. @filipcirtog can you mention this in the guide and include a link to the provider configuration guide with SA?
https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/provider-configuration
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.
Thank you for the suggestions. I have added some notes on this. Please let me know WDY.
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.
Assume same comments as for Org-level steps
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.
Updated! Thank you!
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Migration Example: Organization-Level API Keys to Service Accounts | ||
|
|
||
| This example demonstrates how to migrate from organization-level Programmatic API Key (PAK) resources to Service Account (SA) resources. | ||
|
|
||
| ## Migration Phases | ||
|
|
||
| ### v1: Initial State (PAK Resources) | ||
| Shows the original configuration using PAK resources: | ||
| - `mongodbatlas_api_key` for organization-level API key | ||
| - `mongodbatlas_api_key_project_assignment` for project assignment | ||
| - `mongodbatlas_access_list_api_key` for IP access list entry | ||
|
|
||
| ### v2: Migration Phase (Both PAK and SA Resources) | ||
| Demonstrates the migration approach: | ||
| - Adds Service Account resources alongside existing PAK resources | ||
| - Includes output to capture the Service Account secret | ||
| - Allows testing Service Accounts before removing PAKs | ||
|
|
||
| ### v3: Final State (SA Resources Only) | ||
| Clean final configuration using only: | ||
| - `mongodbatlas_service_account` for organization-level service account | ||
| - `mongodbatlas_service_account_project_assignment` for project assignment | ||
| - `mongodbatlas_service_account_access_list_entry` for IP access list entry | ||
|
|
||
| ## Usage | ||
|
|
||
| 1. Start with v1 to understand the original setup | ||
| 2. Apply v2 configuration to add Service Account resources | ||
| 3. Retrieve and securely store the Service Account secret from the output | ||
| 4. Verify that both PAK and SA authentication methods work correctly | ||
| 5. Apply v3 configuration for the final clean state | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - MongoDB Atlas Terraform Provider with Service Account support | ||
| - Valid MongoDB Atlas organization and project IDs | ||
| - Appropriate permissions to manage API keys and Service Accounts | ||
|
|
||
| ## Variables | ||
|
|
||
| Set these variables for all versions: | ||
|
|
||
| ```terraform | ||
| atlas_client_id = "<ATLAS_CLIENT_ID>" # Optional, can use env vars | ||
| atlas_client_secret = "<ATLAS_CLIENT_SECRET>" # Optional, can use env vars | ||
| org_id = "your-organization-id" | ||
| project_id = "your-project-id" | ||
| org_roles = ["ORG_MEMBER"] | ||
| project_roles = ["GROUP_READ_ONLY", "GROUP_DATA_ACCESS_READ_ONLY"] | ||
| cidr_block = "192.168.1.100/32" | ||
| ``` | ||
|
|
||
| For v2, also set: | ||
filipcirtog marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```terraform | ||
| service_account_name = "example-service-account" # Optional | ||
| secret_expires_after_hours = 2160 # Optional, 90 days default | ||
| ``` | ||
|
|
||
| Alternatively, set environment variables: | ||
| ```bash | ||
| export MONGODB_ATLAS_CLIENT_ID="<ATLAS_CLIENT_ID>" | ||
| export MONGODB_ATLAS_CLIENT_SECRET="<ATLAS_CLIENT_SECRET>" | ||
| ``` | ||
manupedrozo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| ############################################################ | ||
| # v1: Initial State - PAK Resources Only | ||
| ############################################################ | ||
|
|
||
| resource "mongodbatlas_api_key" "this" { | ||
| org_id = var.org_id | ||
| description = "Description for the Organization API Key" | ||
| role_names = var.org_roles | ||
| } | ||
|
|
||
| resource "mongodbatlas_api_key_project_assignment" "this" { | ||
| project_id = var.project_id | ||
| api_key_id = mongodbatlas_api_key.this.api_key_id | ||
| roles = var.project_roles | ||
| } | ||
|
|
||
| resource "mongodbatlas_access_list_api_key" "this" { | ||
| org_id = var.org_id | ||
| api_key_id = mongodbatlas_api_key.this.api_key_id | ||
| cidr_block = var.cidr_block | ||
| # Alternative: ip_address = "192.168.1.100" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| provider "mongodbatlas" { | ||
| client_id = var.atlas_client_id | ||
| client_secret = var.atlas_client_secret | ||
| } |
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.
nit: i'd add a clarification like to use them as authentication mechanism, see more info in: https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/provider-configuration