-
Notifications
You must be signed in to change notification settings - Fork 57
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
use workload identity for external secret instead of service key. #233
Changes from all commits
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 |
---|---|---|
|
@@ -15,10 +15,15 @@ | |
*/ | ||
|
||
|
||
locals { | ||
namespace = "external-secrets" | ||
k8s_sa = "external-secrets" | ||
} | ||
|
||
// External-Secrets | ||
resource "helm_release" "external_secrets" { | ||
name = "external-secrets" | ||
namespace = "external-secrets" | ||
namespace = local.namespace | ||
create_namespace = true | ||
chart = "external-secrets" | ||
repository = "https://charts.external-secrets.io" | ||
|
@@ -42,10 +47,17 @@ resource "google_project_iam_member" "external_secrets_binding" { | |
depends_on = [google_service_account.external_secrets_sa] | ||
} | ||
|
||
resource "google_project_iam_member" "external_secrets_binding_token" { | ||
project = var.project_id | ||
role = "roles/iam.serviceAccountTokenCreator" | ||
member = "serviceAccount:${google_service_account.external_secrets_sa.email}" | ||
depends_on = [google_service_account.external_secrets_sa] | ||
} | ||
|
||
resource "google_service_account_iam_member" "gke_sa_iam_member_external_secrets" { | ||
service_account_id = google_service_account.external_secrets_sa.name | ||
role = "roles/iam.workloadIdentityUser" | ||
member = "serviceAccount:${var.project_id}.svc.id.goog[external-secrets/external-secrets]" | ||
member = "serviceAccount:${var.project_id}.svc.id.goog[${local.namespace}/${local.k8s_sa}]" | ||
depends_on = [google_service_account.external_secrets_sa] | ||
} | ||
|
||
|
@@ -54,27 +66,6 @@ resource "google_service_account_key" "external_secrets_key" { | |
service_account_id = google_service_account.external_secrets_sa.name | ||
} | ||
|
||
resource "kubernetes_secret_v1" "gcpsm_secret" { | ||
metadata { | ||
name = "gcpsm-secret" | ||
namespace = "external-secrets" | ||
annotations = {} | ||
labels = {} | ||
} | ||
|
||
binary_data = { | ||
secret-access-credentials = google_service_account_key.external_secrets_key.private_key | ||
} | ||
|
||
type = "Opaque" | ||
|
||
depends_on = [ | ||
google_service_account.external_secrets_sa, | ||
google_service_account_key.external_secrets_key, | ||
helm_release.external_secrets | ||
] | ||
} | ||
|
||
resource "kubectl_manifest" "secretstore_gcp_backend" { | ||
yaml_body = <<YAML | ||
apiVersion: external-secrets.io/v1alpha1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we can bump to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are still on 0.4.4, i dont think it supports v1beta1 though we should upgrade external secrets to 0.5x There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we don't use anything that breaks, but i will double check |
||
|
@@ -84,19 +75,18 @@ metadata: | |
spec: | ||
provider: | ||
gcpsm: | ||
auth: | ||
secretRef: | ||
secretAccessKeySecretRef: | ||
name: gcpsm-secret | ||
key: secret-access-credentials | ||
namespace: "external-secrets" | ||
projectID: "${var.project_id}" | ||
auth: | ||
workloadIdentity: | ||
clusterLocation: "${var.cluster_location}" | ||
clusterName: "${var.cluster_name}" | ||
clusterProjectID: "${var.project_id}" | ||
serviceAccountRef: | ||
name: local.k8s_sa | ||
namespace: local.namespace | ||
YAML | ||
|
||
depends_on = [ | ||
helm_release.external_secrets, | ||
kubernetes_secret_v1.gcpsm_secret | ||
] | ||
depends_on = [helm_release.external_secrets] | ||
} | ||
|
||
resource "kubectl_manifest" "trillian_namespace" { | ||
|
Check warning
Code scanning / tfsec
Users should not be granted service account access at the project level
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.
Post submit feedback @k4leung4 : can this be updated to grant the role on the specific service accounts(s) that need impersonating? This is a very powerful grant since the external-secrets SA can use access of any other service accounts in the project.
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.
@var-sdk good point. created #264