Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions k8s/bases/infrastructure/vault-config/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,11 @@ spec:
path "secret/data/infrastructure/email/agent" {
capabilities = ["create", "update", "read"]
}
# The SES relay's SMTP credential, pushed from the AccessKey's
# connection Secret (platform#5481). Exact key only.
path "secret/data/infrastructure/email/ses-smtp" {
capabilities = ["create", "update", "read"]
}
path "secret/data/apps/actual-budget/*" {
capabilities = ["create", "update", "read"]
}
Expand Down Expand Up @@ -1135,6 +1140,9 @@ spec:
path "secret/metadata/infrastructure/email/agent" {
capabilities = ["create", "update", "read"]
}
path "secret/metadata/infrastructure/email/ses-smtp" {
capabilities = ["create", "update", "read"]
}
path "secret/metadata/apps/actual-budget/*" {
capabilities = ["create", "update", "read"]
}
Expand Down
28 changes: 28 additions & 0 deletions k8s/providers/hetzner/apps/aws/access-key-email-smtp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# The SMTP credential of company Email's SES relay. The provider publishes the
# key ID as `username` and the SES SMTP password derived for its own region
# (eu-central-1) as `attribute.ses_smtp_password_v4`. The connection Secret
# stays in this namespace; push-secret-email-smtp.yaml copies those two values
# to OpenBao, and nobody reads them. The password is only available when the
# key is created, so the OpenBao copy is the durable one. Rotate by declaring a
# new key, then remove this one with Delete added to its policies.
apiVersion: iam.aws.m.upbound.io/v1beta1
kind: AccessKey
metadata:
name: email-smtp
namespace: aws
labels:
app.kubernetes.io/managed-by: ksail
spec:
managementPolicies:
- Observe
- Create
- Update
- LateInitialize
forProvider:
userRef:
name: email-smtp
writeConnectionSecretToRef:
name: email-smtp-credentials
providerConfigRef:
kind: ProviderConfig
name: default
5 changes: 5 additions & 0 deletions k8s/providers/hetzner/apps/aws/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ resources:
- provider-config.yaml
- policy-eks-ci-smoke-boundary.yaml
- role-eks-ci.yaml
- user-email-smtp.yaml
- policy-email-smtp-send.yaml
- user-policy-attachment-email-smtp.yaml
- access-key-email-smtp.yaml
- push-secret-email-smtp.yaml
- role-ses-account-setup.yaml
- external-secret.yaml
- oci-repository.yaml
Expand Down
40 changes: 40 additions & 0 deletions k8s/providers/hetzner/apps/aws/policy-email-smtp-send.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# The only permission of Company Email's SMTP identity: relay raw mail through
# the company mail domain's SES identity in eu-central-1, with a sender on that
# domain. It cannot read, configure or verify anything in SES.
apiVersion: iam.aws.m.upbound.io/v1beta1
kind: Policy
metadata:
name: email-smtp-send
namespace: aws
labels:
app.kubernetes.io/managed-by: ksail
spec:
managementPolicies:
- Observe
- Create
- Update
- LateInitialize
forProvider:
description: >-
Lets company Email's SMTP identity relay mail through the company mail
domain's SES identity, with a sender on that domain only.
policy: |
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "RelayCompanyMail",
"Effect": "Allow",
"Action": "ses:SendRawEmail",
"Resource": "arn:aws:ses:eu-central-1:939001610192:identity/devantler.tech",
"Condition": {
"StringLike": {
"ses:FromAddress": "*@devantler.tech"
}
}
}
]
}
providerConfigRef:
kind: ProviderConfig
name: default
32 changes: 32 additions & 0 deletions k8s/providers/hetzner/apps/aws/push-secret-email-smtp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copies company Email's SES SMTP credential into OpenBao, where the Email
# server reads it. Platform-applied, so it may use the shared store, which holds
# an exact-key grant for this one record. Replace keeps OpenBao equal to the
# current key; a missing or incomplete connection Secret writes nothing.
apiVersion: external-secrets.io/v1alpha1
kind: PushSecret
metadata:
name: email-smtp-credentials
namespace: aws
labels:
app.kubernetes.io/managed-by: ksail
spec:
updatePolicy: Replace
deletionPolicy: None
refreshInterval: 1h
secretStoreRefs:
- name: openbao
kind: ClusterSecretStore
selector:
secret:
name: email-smtp-credentials
data:
- match:
secretKey: username
remoteRef:
remoteKey: infrastructure/email/ses-smtp
property: username
- match:
secretKey: attribute.ses_smtp_password_v4
remoteRef:
remoteKey: infrastructure/email/ses-smtp
property: password
23 changes: 23 additions & 0 deletions k8s/providers/hetzner/apps/aws/user-email-smtp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Company Email's send-only SMTP identity for the Amazon SES relay
# (platform#5481). Platform-owned for the same reason as the EKS CI role: the
# public aws tenant must not be able to widen what this credential may do.
# Delete is omitted so a prune cannot remove the identity outbound mail uses;
# revoke by replacing its access key instead.
apiVersion: iam.aws.m.upbound.io/v1beta1
kind: User
metadata:
name: email-smtp
namespace: aws
labels:
app.kubernetes.io/managed-by: ksail
spec:
managementPolicies:
- Observe
- Create
- Update
- LateInitialize
forProvider:
path: /email/
providerConfigRef:
kind: ProviderConfig
name: default
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Attaches the send-only policy to company Email's SMTP identity.
apiVersion: iam.aws.m.upbound.io/v1beta1
kind: UserPolicyAttachment
metadata:
name: email-smtp-send
namespace: aws
labels:
app.kubernetes.io/managed-by: ksail
spec:
managementPolicies:
- Observe
- Create
- Update
- LateInitialize
forProvider:
userRef:
name: email-smtp
policyArnRef:
name: email-smtp-send
providerConfigRef:
kind: ProviderConfig
name: default
24 changes: 21 additions & 3 deletions scripts/tests/arc-staging/mail_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,20 @@ func TestPrivateMailCredentialsHaveExactSeedAndReadAuthorization(t *testing.T) {
}
_, policy := captureBaoWrite(t, "bao", "policy", "write", "vault-seed-write")
entries := regexp.MustCompile(`(?s)path\s+"(secret/(?:data|metadata)/infrastructure/email/[^\"]+)"\s*\{\s*capabilities\s*=\s*(\[[^\]]+\])\s*\}`).FindAllStringSubmatch(policy, -1)
// The three mailbox credentials, plus the SES relay's SMTP credential that a
// platform-applied PushSecret copies from its AccessKey (platform#5481).
want := map[string]bool{}
for _, kind := range []string{"data", "metadata"} {
for _, account := range []string{"admin", "maintainer", "agent"} {
want["secret/"+kind+"/infrastructure/email/"+account] = true
for _, credential := range []string{"admin", "maintainer", "agent", "ses-smtp"} {
want["secret/"+kind+"/infrastructure/email/"+credential] = true
}
}
if len(entries) != len(want) {
t.Fatalf("need one exact data and metadata grant per mail credential, got %d", len(entries))
}
for _, entry := range entries {
if !want[entry[1]] {
t.Fatal("mail credential authorization is duplicated or broader than its three entries")
t.Fatal("mail credential authorization is duplicated or broader than its four entries")
}
delete(want, entry[1])
var capabilities []string
Expand Down Expand Up @@ -81,6 +83,22 @@ func TestPrivateMailCredentialsHaveExactSeedAndReadAuthorization(t *testing.T) {
equal(t, mailField[string](t, seed, "spec", "updatePolicy"), "IfNotExists")
equal(t, mailField[string](t, seed, "spec", "deletionPolicy"), "None")
}
// The relay credential follows its AccessKey, so it replaces rather than
// seeds, and it writes only the username and SMTP password of that one key.
relay := readYAML(t, "k8s/providers/hetzner/apps/aws/push-secret-email-smtp.yaml")
equal(t, mailField[string](t, relay, "metadata", "namespace"), "aws")
equal(t, mailField[string](t, relay, "spec", "selector", "secret", "name"), "email-smtp-credentials")
equal(t, mailField[string](t, relay, "spec", "updatePolicy"), "Replace")
equal(t, mailField[string](t, relay, "spec", "deletionPolicy"), "None")
relayData := mailField[[]any](t, relay, "spec", "data")
equal(t, len(relayData), 2)
pushed := map[string]string{}
for _, entry := range relayData {
equal(t, mailField[string](t, entry, "match", "remoteRef", "remoteKey"), "infrastructure/email/ses-smtp")
pushed[mailField[string](t, entry, "match", "secretKey")] = mailField[string](t, entry, "match", "remoteRef", "property")
}
equal(t, pushed["username"], "username")
equal(t, pushed["attribute.ses_smtp_password_v4"], "password")
}

// Match the first node rule exactly as declared, including catch-all precedence.
Expand Down
8 changes: 8 additions & 0 deletions scripts/validate-eks-ci-role-policy/approved-surface.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,20 @@ helm.toolkit.fluxcd.io/v2|HelmRelease|vertical-pod-autoscaler|vertical-pod-autos

helm.toolkit.fluxcd.io/v2|HelmRelease|whoami|whoami 22eb185e9f69bbddf8dc27bd2a852b07b3bbaf791d25ada894eeb8e954f99bed

iam.aws.m.upbound.io/v1beta1|AccessKey|aws|email-smtp 22ff8010a4298f2b19a2829a65c383f27fd737b2aed7b096f22814ad73a2f240

iam.aws.m.upbound.io/v1beta1|Policy|aws|eks-ci-smoke-boundary 019210611429956763cab81a883bc6cf1faf53caf89b5e9274e8ec69cad01b66

iam.aws.m.upbound.io/v1beta1|Policy|aws|email-smtp-send 38284030cdef086fa0a51443feba839b2f6fcf27bf1cc177fa2fa15d314ceb30

iam.aws.m.upbound.io/v1beta1|Role|aws|eks-ci c40205b3f48d193e8be1a39abda738865b954c90733039a49854f0bac5844306

iam.aws.m.upbound.io/v1beta1|Role|aws|ses-account-setup 7faa58457f4a17a3c14368d3a956bb07da4f40bb2689c61149ee31eae9693b6b

iam.aws.m.upbound.io/v1beta1|UserPolicyAttachment|aws|email-smtp-send 06c8f5c0aa8f7b593878b9869c5af7375a1ef2f429182cb904e76e0dae966e1c

iam.aws.m.upbound.io/v1beta1|User|aws|email-smtp 19ce46105be088b444658d4d594f6059308f079440336af06af912d60aeb5704

kro.run/v1alpha1|ResourceGraphDefinition||tenant.kro.run 72f3f972cecdf3ca2e315deb4224bd28c1df1244fc7973a88eb7f4fc03ac1d05

kro.run/v1alpha1|Tenant|flux-system|business-site 47380ca8c8781c2de6b17226e44ac7cef030e13a89c8b41dae9ddf459304b3a4
Expand Down
Loading