Terraform 如何轮换 Azure AD 应用机密
How Terraform rotate Azure AD app secrets
我正在尝试使用 Terraform 执行 azure 服务原则密码轮换,他们使用最新版本的 azuread 提供了此轮换功能,
resource "time_rotating" "test" {
rotation_years = 5
lifecycle {
create_before_destroy = true
}
}
resource "azuread_service_principal_password" "service_principal_password" {
service_principal_id = var.sp_internal_id
rotate_when_changed = {
rotation = time_rotating.test.id
}
lifecycle {
create_before_destroy = true
}
}
我只想在添加属性时 rotate_when_changed 它会根据我设置的时间戳创建一个新的密码资源,对吗?我想知道这是 Terraform 只提供的功能还是 Azure AD 的功能?由于 Azure AD 不提供密钥轮换功能,我想知道 Terraform 如何实现这种轮换?
I just want to when I add the attribute rotate_when_changed it will
create a new password resource according to the timestamp I set right
? and I want to know that this is a feature that Terraform only
provides or this is a feature from Azure AD ? since Azure AD does not
provide the key rotation feature, I'm wondering how Terraform is
achieving this rotation ?
你是对的,它只是一个 terraform 功能,不是 AzureAD 功能。当我们从 terraform 创建密码时,它不再使用值,如果您没有提供任何 end_date_relative
,那么它将过期设置为默认值 2 年。但是出于安全原因,如果我们想根据时间轮换更改密码的值,那么我们可以设置 rotate_when_changed
并修改它。
在此 GitHub Issue 中建议并增强了这一点。
示例:
我使用下面的代码在一小时后旋转值:
resource "time_rotating" "test" {
rotation_hours = 1
lifecycle {
create_before_destroy = true
}
}
resource "azuread_application_password" "example" {
application_object_id = azuread_application.example.object_id
rotate_when_changed = {
rotation = time_rotating.test.id
}
lifecycle {
create_before_destroy = true
}
}
初始输出:
如果我执行 terraform Plan 1 小时后,它会显示密码将被替换如下,但在 1 小时之前它只会显示未检测到任何更改:
注意:这很有用,因为您不必再次销毁密码块并重新创建它。只有当你的时间轮换完成时,如果你执行应用,那么 terraform 将只替换密码块并再次根据你的要求设置时间轮换。
我正在尝试使用 Terraform 执行 azure 服务原则密码轮换,他们使用最新版本的 azuread 提供了此轮换功能,
resource "time_rotating" "test" {
rotation_years = 5
lifecycle {
create_before_destroy = true
}
}
resource "azuread_service_principal_password" "service_principal_password" {
service_principal_id = var.sp_internal_id
rotate_when_changed = {
rotation = time_rotating.test.id
}
lifecycle {
create_before_destroy = true
}
}
我只想在添加属性时 rotate_when_changed 它会根据我设置的时间戳创建一个新的密码资源,对吗?我想知道这是 Terraform 只提供的功能还是 Azure AD 的功能?由于 Azure AD 不提供密钥轮换功能,我想知道 Terraform 如何实现这种轮换?
I just want to when I add the attribute rotate_when_changed it will create a new password resource according to the timestamp I set right ? and I want to know that this is a feature that Terraform only provides or this is a feature from Azure AD ? since Azure AD does not provide the key rotation feature, I'm wondering how Terraform is achieving this rotation ?
你是对的,它只是一个 terraform 功能,不是 AzureAD 功能。当我们从 terraform 创建密码时,它不再使用值,如果您没有提供任何 end_date_relative
,那么它将过期设置为默认值 2 年。但是出于安全原因,如果我们想根据时间轮换更改密码的值,那么我们可以设置 rotate_when_changed
并修改它。
在此 GitHub Issue 中建议并增强了这一点。
示例:
我使用下面的代码在一小时后旋转值:
resource "time_rotating" "test" {
rotation_hours = 1
lifecycle {
create_before_destroy = true
}
}
resource "azuread_application_password" "example" {
application_object_id = azuread_application.example.object_id
rotate_when_changed = {
rotation = time_rotating.test.id
}
lifecycle {
create_before_destroy = true
}
}
初始输出:
如果我执行 terraform Plan 1 小时后,它会显示密码将被替换如下,但在 1 小时之前它只会显示未检测到任何更改:
注意:这很有用,因为您不必再次销毁密码块并重新创建它。只有当你的时间轮换完成时,如果你执行应用,那么 terraform 将只替换密码块并再次根据你的要求设置时间轮换。