다음 예는 다양한 액세스 유형에 대한 인증 및 권한 부여 사항을 구현 방법을 보여줍니다. 예제에서는 Atlas CLI 와 Terraform을 모두 사용하여 권장 사항을 구현 방법을 보여줍니다.
Terraform에 대해 학습 Terraform 시작하기 및 MongoDB Atlas 제공자 및 MongoDB Atlas 제공자 Terraform 문서를 참조하세요.
Atlas UI
Atlas UI 에 액세스 하려면 다음을 수행합니다.
IP 액세스 목록을 구현합니다. 예시 를 들어,
atlas organizations apiKeys accessLists create --apiKey <API_KEY_ID> --ip <IP_ADDRESS> 페더레이션 인증 또는 Atlas 자격 증명 및 다단계 인증(MFA)을 구현합니다.
페더레이션 인증을 설정하다 하려면 atlas-federatedAuthentication 및 관련 명령을 사용합니다. 그런 다음 atlas-users-invite 명령을 사용하여 조직 및 프로젝트에 사용자를 초대할 수 있습니다.
시작하려면 다음 명령을 사용하세요.
atlas federatedAuthentication --help 참고
SSO로 인증하는 사용자의 경우 SSO ID 제공자도 구성해야 합니다.
자세한 내용은 페더레이션 인증 구성을 참조하세요.
데이터베이스 액세스
인력(인적) 액세스
인력 데이터베이스 액세스 의 경우:
Atlas-dbusers-certs-create 명령을 사용하여 Atlas 관리형 MFA(Multi-Factor509 Authentication) X. 클라이언트 인증서를 생성합니다.
참고
자체 관리형 인증서를 사용하려면 먼저 X를 구성해야509 합니다.:
atlas dbusers certs create --username <USERNAME> --projectId <PROJECT_ID> [--monthsUntilExpiration <MONTHS>] [--output json]
워크로드(시스템) 액세스
워크로드 (시스템) 액세스 의 경우 Workload Identity Federation을 사용하세요.
API 액세스
serviceAccounts 및 관련 명령을 사용하여 서비스 계정을 만들고 관리 . 예시 를 들어,
atlas api serviceAccounts createServiceAccount [options]
개발 및 테스트 환경의 경우 API 키를 사용할 수도 있습니다. 예시 를 들어,
atlas organizations apiKeys create [options]
다음 예시는 인증 및 권한 부여를 구성하는 방법을 보여줍니다. Terraform으로 리소스를 생성하려면:
결제 조직을 생성하고 해당 결제 조직에 대한 API 키를 생성합니다. 터미널에서 다음 명령을 실행하여 API 키를 환경 변수로 저장하세요.
export MONGODB_ATLAS_PUBLIC_KEY="<insert your public key here>" export MONGODB_ATLAS_PRIVATE_KEY="<insert your private key here>"
공용 파일
각 예시 에 대해 다음 파일을 만들어야 합니다. 각 예시 에 대한 파일을 자체 디렉토리 에 배치합니다. 값을 사용하려면 ID와 이름을 변경합니다. 그런 다음 명령을 실행 Terraform을 초기화하고, Terraform 계획을 확인한 다음 변경 사항을 적용 .
azure.tf
locals { tags = { CreatedBy = "Terraform" Owner = var.owner Module = "tf-example-oidc-azure" Name = var.project_name } } resource "azurerm_resource_group" "this" { name = var.project_name location = var.location tags = local.tags } resource "azurerm_virtual_network" "this" { name = var.project_name address_space = ["10.0.0.0/16"] location = azurerm_resource_group.this.location resource_group_name = azurerm_resource_group.this.name tags = local.tags } resource "azurerm_subnet" "internal" { name = "internal" resource_group_name = azurerm_resource_group.this.name virtual_network_name = azurerm_virtual_network.this.name address_prefixes = ["10.0.2.0/24"] } resource "azurerm_public_ip" "vm-public-ip" { name = "public-ip-${var.project_name}" location = var.location resource_group_name = azurerm_resource_group.this.name allocation_method = "Dynamic" domain_name_label = var.project_name tags = local.tags } resource "azurerm_network_interface" "this" { name = "ip-${var.project_name}" location = var.location resource_group_name = azurerm_resource_group.this.name tags = local.tags ip_configuration { subnet_id = azurerm_subnet.internal.id name = "public" private_ip_address_allocation = "Dynamic" public_ip_address_id = azurerm_public_ip.vm-public-ip.id } } resource "azurerm_user_assigned_identity" "this" { location = var.location name = var.project_name resource_group_name = azurerm_resource_group.this.name tags = local.tags } resource "azurerm_linux_virtual_machine" "this" { name = var.project_name resource_group_name = azurerm_resource_group.this.name location = var.location size = "Standard_F2" admin_username = var.vm_admin_username custom_data = data.cloudinit_config.this.rendered network_interface_ids = [azurerm_network_interface.this.id] tags = local.tags admin_ssh_key { username = var.vm_admin_username public_key = var.ssh_public_key } source_image_reference { publisher = "Canonical" offer = "0001-com-ubuntu-server-jammy" sku = "22_04-lts" version = "latest" } os_disk { storage_account_type = "Standard_LRS" caching = "ReadWrite" disk_size_gb = 30 } identity { type = "UserAssigned" identity_ids = [azurerm_user_assigned_identity.this.id] } }
variables.tf
# Azure Variables variable "token_audience" { type = string default = "https://management.azure.com/" description = "Used as resource when getting the access token. See more in the [Azure documentation](https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/how-to-use-vm-token#get-a-token-using-http)" } # MongoDB Atlas variables variable "org_id" { type = string description = "MongoDB Atlas Organization ID" } variable "project_id" { type = string description = "MongoDB Atlas Project ID" } variable "project_name" { type = string description = "MongoDB Atlas Project Name" } variable "connection_strings" { type = list(string) description = "MongoDB Atlas Cluster Standard Connection Strings" }
terraform.tfvars
org_id = "32b6e34b3d91647abb20e7b8" project_id = "67212db237c5766221eb6ad9" project_name = "My Project" connection_strings = token_audience = "https://management.azure.com/"
outputs.tf
output "vm_fqdn" { value = azurerm_public_ip.vm-public-ip.fqdn description = "Fully Qualified Domain Name (FQDN) of the Virtual Machine (VM)" } output "ssh_connection_string" { value = "ssh ${var.vm_admin_username}@${azurerm_public_ip.vm-public-ip.fqdn}" description = "Useful for connecting to the instance" } output "user_test_conn_string" { value = "mongodb+srv://${local.test_user_username}:${local.test_user_password}@${replace(mongodbatlas_advanced_cluster.this.connection_strings[0].standard_srv, "mongodb+srv://", "")}/?retryWrites=true" sensitive = true description = "Useful for connecting to the database from Compass or other tool to validate data" } output "user_oidc_conn_string" { value = local.mongodb_oidc_uri sensitive = true description = "Useful to see the format of the OIDC connection string" }
ID 제공자에 대한 페더레이션 설정 구성
다음을 사용하여 Azure 에서 사용하기 위해 Atlas 에서OIDC 페더레이션 ID 제공자 설정하다 합니다.Azure Active Directory에서 발급한 OIDC 토큰을 사용하여 액세스 할 수 있습니다.
# Connection string to use in this configuration locals { mongodb_uri = var.connection_strings[0] } # Atlas organization details to use in the configuration data "mongodbatlas_federated_settings" "this" { org_id = var.org_id name = var.project_name project_id = var.project_id } # Configure an identity provider for federated authentication resource "mongodbatlas_federated_settings_identity_provider" "oidc" { federation_settings_id = data.mongodbatlas_federated_settings.this.id audience = var.token_audience authorization_type = "USER" description = "oidc-for-azure" # e.g. "https://sts.windows.net/91405384-d71e-47f5-92dd-759e272cdc1c/" issuer_uri = "https://sts.windows.net/${azurerm_user_assigned_identity.this.tenant_id}/" idp_type = "WORKLOAD" name = "OIDC-for-azure" protocol = "OIDC" # groups_claim = null user_claim = "sub" } resource "mongodbatlas_federated_settings_org_config" "this" { federation_settings_id = data.mongodbatlas_federated_settings.this.id org_id = var.org_id domain_restriction_enabled = false domain_allow_list = [] data_access_identity_provider_ids = [mongodbatlas_federated_settings_identity_provider.oidc.idp_id] }
다음을 사용하여 OIDC 페더레이션 인증 사용자를 생성합니다.
resource "mongodbatlas_database_user" "oidc" { project_id = var.project_id username = "${mongodbatlas_federated_settings_identity_provider.oidc.idp_id}/${azurerm_user_assigned_identity.this.principal_id}" oidc_auth_type = "USER" auth_database_name = "$external" # required when using OIDC USER authentication roles { role_name = "atlasAdmin" database_name = "admin" } }
사용자 지정 역할 구성
다음을 사용하여 이름이 myDb
인 데이터베이스 의 모든 컬렉션 에 대해 업데이트, 추가 및 삭제 작업을 허용하는 my_custom_role
이라는 사용자 지정 역할 만듭니다.
resource "mongodbatlas_custom_db_role" "create_role" { project_id = var.project_id role_name = "my_custom_role" actions { action = "UPDATE" resources { database_name = "myDb" } } actions { action = "INSERT" resources { database_name = "myDb" } } actions { action = "REMOVE" resources { database_name = "myDb" } } }
특정 그룹에 Atlas 역할 할당된 Atlas 프로젝트의 예시는 예제를 참조하세요.