feat(cluster_issuer): support keyless AWS auth for Route53 solver (#3887)

Signed-off-by: Mohammed Naser <mnaser@vexxhost.com>
Signed-off-by: okozachenko <okozachenko@vexxhost.com>
Signed-off-by: donnyao <ao.donny@gmail.com>
Co-authored-by: okozachenko <okozachenko@vexxhost.com>
Co-authored-by: donnyao <ao.donny@gmail.com>
This commit is contained in:
authored and GitHub committed 2026-06-17 10:50:47 -04:00
1 parent 7b2922238a
commit 8fac3d55c1
4 files changed
+515 -29

No files matched your search

+374 -2
View File
@@ -175,13 +175,41 @@ challenges with the following configuration:
Route53
*******
If you are using Route53 to host the DNS for your domains, you can use the
following configuration:
If you are using Route53 to host the DNS for your domains, the ``cluster_issuer``
role supports three authentication modes, selected with
``cluster_issuer_acme_route53_auth``.
The supported modes are:
.. list-table::
:header-rows: 1
* - Mode
- Description
- Uses long-lived AWS keys
* - ``static``
- Uses an IAM access key and secret access key.
- Yes
* - ``ambient``
- Uses credentials from the ``cert-manager`` pod environment, such as
environment variables, an EC2 instance profile, or a mounted AWS
credentials file.
- No
* - ``kubernetes``
- Uses OIDC-based ``sts:AssumeRoleWithWebIdentity`` with a projected
ServiceAccount token.
- No
Static access key (default)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Authenticate with a long-lived IAM user access key and secret access key:
.. code-block:: yaml
cluster_issuer_acme_email: user@example.com
cluster_issuer_acme_solver: route53
cluster_issuer_acme_route53_auth: static
cluster_issuer_acme_route53_region: <REGION>
cluster_issuer_acme_route53_hosted_zone_id: <HOSTED_ZONE_ID>
cluster_issuer_acme_route53_access_key_id: <AWS_ACCESS_KEY_ID>
@@ -192,6 +220,350 @@ following configuration:
You'll need to make sure that your AWS credentials have the correct
permissions to update the Route53 zone.
Ambient credentials
^^^^^^^^^^^^^^^^^^^
Let ``cert-manager`` pick up credentials from its pod environment (for
example, the EC2 instance metadata service or a credentials file mounted into
the controller pod). No secrets are stored in the cluster.
.. code-block:: yaml
cluster_issuer_acme_email: user@example.com
cluster_issuer_acme_solver: route53
cluster_issuer_acme_route53_auth: ambient
cluster_issuer_acme_route53_region: <REGION>
cluster_issuer_acme_route53_hosted_zone_id: <HOSTED_ZONE_ID>
# Optional: role to assume once ambient credentials are resolved.
cluster_issuer_acme_route53_role_arn: <IAM_ROLE_ARN>
This mode needs the environment hosting ``cert-manager`` to already expose
AWS credentials through the default AWS SDK credential chain, which
typically means running on AWS infrastructure. If
``cluster_issuer_acme_route53_role_arn`` is set, ``cert-manager`` assumes that
role after resolving the ambient credentials.
Ambient mode can also support IAM Roles Anywhere when the ``cert-manager`` pod
is augmented with the ``aws_signing_helper`` binary and an ``~/.aws/config``
entry that points to it with ``credential_process``. That wiring is outside the
scope of the ``cluster_issuer`` role.
Kubernetes OIDC (keyless)
^^^^^^^^^^^^^^^^^^^^^^^^^
For operators whose policy forbids long-lived AWS keys, ``cert-manager`` can
assume an IAM role using a projected ServiceAccount token. This works with any
Kubernetes cluster, including on-premises, and doesn't require the cluster to
run on AWS.
.. code-block:: yaml
cluster_issuer_acme_email: user@example.com
cluster_issuer_acme_solver: route53
cluster_issuer_acme_route53_auth: kubernetes
cluster_issuer_acme_route53_region: <REGION>
cluster_issuer_acme_route53_hosted_zone_id: <HOSTED_ZONE_ID>
cluster_issuer_acme_route53_role_arn: <IAM_ROLE_ARN>
# Optional; defaults to "cert-manager-route53".
cluster_issuer_acme_route53_service_account_name: cert-manager-route53
The role creates a ``ServiceAccount`` in the ``cert-manager`` namespace and
allows the ``cert-manager`` controller to request projected tokens for it. The
solver then references that ServiceAccount, and ``cert-manager`` exchanges the
short-lived token for temporary AWS credentials with
``sts:AssumeRoleWithWebIdentity``.
.. note::
This configuration requires cert-manager v1.15.0 or newer CRDs. Older
cert-manager CRDs do not include the Route53
``auth.kubernetes.serviceAccountRef`` schema, so upgrade cert-manager before
applying this solver configuration.
The AWS IAM OIDC provider, trust policy, and Route53 permissions are external
prerequisites. Complete the following one-time setup for each Kubernetes cluster
before applying the Atmosphere configuration.
Publish OIDC discovery documents
""""""""""""""""""""""""""""""""
#. Choose the public issuer URL that AWS IAM will use to verify Kubernetes
ServiceAccount tokens. The following example publishes the OIDC documents in
a dedicated S3 bucket:
.. code-block:: shell
S3_BUCKET_NAME="my-oidc-bucket"
AWS_REGION="eu-west-1"
ISSUER_HOSTPATH="${S3_BUCKET_NAME}.s3.${AWS_REGION}.amazonaws.com"
You can also use a custom domain or another public HTTPS endpoint. The key
requirement is that AWS IAM can reach the issuer URL over HTTPS.
#. Create the S3 bucket:
.. code-block:: shell
aws s3api create-bucket \
--bucket "${S3_BUCKET_NAME}" \
--region "${AWS_REGION}" \
--create-bucket-configuration "LocationConstraint=${AWS_REGION}"
#. Fetch the OIDC discovery documents from the Kubernetes API server:
.. code-block:: shell
kubectl get --raw /openid/v1/jwks > jwks.json
kubectl get --raw /.well-known/openid-configuration > openid-configuration.json
If you do not have direct API access from your workstation, use
``kubectl proxy`` and fetch the same paths through the local proxy:
.. code-block:: shell
kubectl proxy &
curl http://127.0.0.1:8001/openid/v1/jwks > jwks.json
curl http://127.0.0.1:8001/.well-known/openid-configuration > openid-configuration.json
#. Rewrite the discovery document so both ``issuer`` and ``jwks_uri`` point to
the public issuer URL:
.. code-block:: shell
jq --arg uri "https://${ISSUER_HOSTPATH}/openid/v1/jwks" \
'.jwks_uri = $uri' \
openid-configuration.json > openid-configuration-updated.json
jq --arg iss "https://${ISSUER_HOSTPATH}" \
'.issuer = $iss' \
openid-configuration-updated.json > openid-configuration-final.json
#. Upload the discovery documents:
.. code-block:: shell
aws s3 cp jwks.json \
"s3://${S3_BUCKET_NAME}/openid/v1/jwks" \
--content-type "application/json"
aws s3 cp openid-configuration-final.json \
"s3://${S3_BUCKET_NAME}/.well-known/openid-configuration" \
--content-type "application/json"
#. Allow unauthenticated reads for only the published OIDC documents. Use a
dedicated bucket because these objects must be public:
.. code-block:: shell
aws s3api put-public-access-block \
--bucket "${S3_BUCKET_NAME}" \
--public-access-block-configuration \
"BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false"
cat > bucket-policy.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": [
"arn:aws:s3:::${S3_BUCKET_NAME}/.well-known/openid-configuration",
"arn:aws:s3:::${S3_BUCKET_NAME}/openid/v1/jwks"
]
}
]
}
EOF
aws s3api put-bucket-policy \
--bucket "${S3_BUCKET_NAME}" \
--policy file://bucket-policy.json
#. Verify that both public endpoints return valid JSON:
.. code-block:: shell
curl "https://${ISSUER_HOSTPATH}/.well-known/openid-configuration"
curl "https://${ISSUER_HOSTPATH}/openid/v1/jwks"
Configure the Kubernetes API server
"""""""""""""""""""""""""""""""""""
The Kubernetes API server must use the public issuer URL so the projected
tokens it mints are verifiable by AWS. On every control plane node, update the
static pod manifest for ``kube-apiserver``.
Replace an existing issuer flag such as:
.. code-block:: yaml
- --service-account-issuer=https://kubernetes.default.svc.cluster.local
with the issuer configuration:
.. code-block:: yaml
- --service-account-issuer=https://<ISSUER_HOSTPATH>
- --service-account-issuer=https://kubernetes.default.svc.cluster.local
- --service-account-jwks-uri=https://<ISSUER_HOSTPATH>/openid/v1/jwks
- --api-audiences=https://kubernetes.default.svc.cluster.local,https://<ISSUER_HOSTPATH>,sts.amazonaws.com
Replace ``<ISSUER_HOSTPATH>`` with the host path you published, such as
``my-oidc-bucket.s3.eu-west-1.amazonaws.com``. After you save the manifest, the
kubelet restarts the ``kube-apiserver`` pod automatically.
Verify the token issuer and audience with a temporary pod:
.. code-block:: shell
kubectl run token-test --image=busybox --restart=Never -- sleep 3600
kubectl exec token-test -- cat /run/secrets/kubernetes.io/serviceaccount/token
Decode the token with a JWT decoder and verify that ``iss`` is
``https://<ISSUER_HOSTPATH>`` and that ``aud`` includes
``https://kubernetes.default.svc.cluster.local``, ``https://<ISSUER_HOSTPATH>``,
and ``sts.amazonaws.com``.
Remove the temporary pod when you are done:
.. code-block:: shell
kubectl delete pod token-test
Configure AWS IAM
"""""""""""""""""
#. Register the issuer URL as an OIDC provider in AWS IAM:
.. code-block:: shell
THUMBPRINT=$(openssl s_client \
-connect "${ISSUER_HOSTPATH}:443" \
-servername "${ISSUER_HOSTPATH}" \
</dev/null 2>/dev/null | \
openssl x509 -fingerprint -noout | sed 's/://g' | cut -d= -f2)
aws iam create-open-id-connect-provider \
--url "https://${ISSUER_HOSTPATH}" \
--client-id-list sts.amazonaws.com \
--thumbprint-list "${THUMBPRINT}"
#. Create an IAM role with a trust policy restricted to the Route53
ServiceAccount:
.. code-block:: shell
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
OIDC_PROVIDER="${ISSUER_HOSTPATH}"
cat > trust-policy.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::${ACCOUNT_ID}:oidc-provider/${OIDC_PROVIDER}"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"${OIDC_PROVIDER}:sub": "system:serviceaccount:cert-manager:cert-manager-route53",
"${OIDC_PROVIDER}:aud": "sts.amazonaws.com"
}
}
}
]
}
EOF
aws iam create-role \
--role-name cert-manager-route53 \
--assume-role-policy-document file://trust-policy.json
If you set ``cluster_issuer_acme_route53_service_account_name`` to a custom
name, use that name in the trust policy subject instead of
``cert-manager-route53``.
#. Attach the Route53 permissions that cert-manager needs for DNS-01
challenges:
.. code-block:: shell
cat > route53-policy.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"route53:GetChange",
"route53:ChangeResourceRecordSets",
"route53:ListHostedZonesByName"
],
"Resource": "*"
}
]
}
EOF
aws iam put-role-policy \
--role-name cert-manager-route53 \
--policy-name Route53Access \
--policy-document file://route53-policy.json
Apply the Atmosphere configuration
""""""""""""""""""""""""""""""""""
After the OIDC issuer and IAM role are ready, set the Atmosphere variables and
run the playbook:
.. code-block:: yaml
cluster_issuer_acme_email: user@example.com
cluster_issuer_acme_solver: route53
cluster_issuer_acme_route53_auth: kubernetes
cluster_issuer_acme_route53_region: <REGION>
cluster_issuer_acme_route53_hosted_zone_id: <HOSTED_ZONE_ID>
cluster_issuer_acme_route53_role_arn: arn:aws:iam::123456789012:role/cert-manager-route53
Route53 variables
^^^^^^^^^^^^^^^^^
.. list-table::
:header-rows: 1
* - Variable
- Default
- Description
* - ``cluster_issuer_acme_route53_auth``
- ``static``
- Authentication mode. Set to ``static``, ``ambient``, or ``kubernetes``.
* - ``cluster_issuer_acme_route53_region``
- Not set
- AWS region for Route53 API calls.
* - ``cluster_issuer_acme_route53_hosted_zone_id``
- Not set
- Route53 hosted zone ID.
* - ``cluster_issuer_acme_route53_access_key_id``
- Not set
- IAM access key ID for ``static`` mode.
* - ``cluster_issuer_acme_route53_secret_access_key``
- Not set
- IAM secret access key for ``static`` mode.
* - ``cluster_issuer_acme_route53_role_arn``
- Not set
- IAM role ARN to assume. This is required for ``kubernetes`` mode and
optional for ``static`` and ``ambient`` modes.
* - ``cluster_issuer_acme_route53_service_account_name``
- ``cert-manager-route53``
- ServiceAccount name for ``kubernetes`` mode.
* - ``cluster_issuer_acme_route53_secret_name``
- ``cert-manager-issuer-route53-credentials``
- Kubernetes Secret name for static credentials.
Cloudflare
**********
@@ -0,0 +1,20 @@
---
features:
- |
The Route53 DNS-01 solver for the ``cluster_issuer`` role now supports
keyless AWS authentication alongside the existing long-lived access
key flow. A new ``cluster_issuer_acme_route53_auth`` variable selects the
authentication mode, which can use static access keys (the default),
ambient credentials picked up from the pod environment, or OIDC-based
``AssumeRoleWithWebIdentity`` using a projected ServiceAccount token.
The OIDC mode works with any Kubernetes cluster whose service account
issuer is publicly resolvable by AWS, including on-premises clusters, and
removes the need for long-lived IAM credentials.
A new ``cluster_issuer_acme_route53_role_arn`` variable also sets the IAM
role ARN to assume. The OIDC mode needs this variable.
upgrade:
- |
The default Route53 authentication mode remains ``static``, so existing
deployments continue to work without changes.
+16
View File
@@ -44,9 +44,25 @@ cluster_issuer_acme_rfc2136_secret_name: cert-manager-issuer-tsig-secret-key
# cluster_issuer_acme_rfc2136_tsig_key_name: <KEY_NAME>
# cluster_issuer_acme_rfc2136_tsig_secret_key: <SECRET_KEY>
# Authentication mode for the Route53 solver. One of:
# - "static": long-lived IAM user access key / secret access key (default,
# backwards compatible).
# - "ambient": cert-manager uses ambient credentials from the pod's
# environment (env vars, EC2 IMDS, mounted credentials file,
# etc.). Enabled by default for ClusterIssuers upstream.
# - "kubernetes": cert-manager performs AssumeRoleWithWebIdentity using a
# projected token for a dedicated ServiceAccount in the
# cert-manager namespace. The cluster's OIDC issuer must be
# registered as an IAM identity provider in AWS, and the
# target IAM role must trust that provider and the
# ServiceAccount. Requires
# ``cluster_issuer_acme_route53_role_arn`` to be set.
cluster_issuer_acme_route53_auth: static
cluster_issuer_acme_route53_secret_name: cert-manager-issuer-route53-credentials
cluster_issuer_acme_route53_service_account_name: cert-manager-route53
# cluster_issuer_acme_route53_region: <REGION>
# cluster_issuer_acme_route53_hosted_zone_id: <HOSTED_ZONE_ID>
# cluster_issuer_acme_route53_role_arn: <IAM_ROLE_ARN>
# cluster_issuer_acme_route53_access_key_id: <AWS_ACCESS_KEY_ID>
# cluster_issuer_acme_route53_secret_access_key: <AWS_SECRET_ACCESS_KEY>
@@ -12,36 +12,114 @@
# License for the specific language governing permissions and limitations
# under the License.
- name: Create ClusterIssuer
- name: Validate Route53 authentication mode
run_once: true
ansible.builtin.assert:
that:
- cluster_issuer_acme_route53_auth in ["static", "ambient", "kubernetes"]
fail_msg: >-
cluster_issuer_acme_route53_auth must be one of:
"static", "ambient", "kubernetes".
- name: Create Route53 credentials Secret
run_once: true
when: cluster_issuer_acme_route53_auth == "static"
kubernetes.core.k8s:
state: present
definition:
- apiVersion: v1
kind: Secret
metadata:
name: "{{ cluster_issuer_acme_route53_secret_name }}"
namespace: cert-manager
type: Opaque
stringData:
secret-access-key: "{{ cluster_issuer_acme_route53_secret_access_key }}"
apiVersion: v1
kind: Secret
metadata:
name: "{{ cluster_issuer_acme_route53_secret_name }}"
namespace: cert-manager
type: Opaque
stringData:
secret-access-key: "{{ cluster_issuer_acme_route53_secret_access_key }}"
- apiVersion: cert-manager.io/v1
kind: ClusterIssuer
- name: Create Route53 ServiceAccount for AssumeRoleWithWebIdentity
run_once: true
when: cluster_issuer_acme_route53_auth == "kubernetes"
kubernetes.core.k8s:
state: present
definition:
apiVersion: v1
kind: ServiceAccount
metadata:
name: "{{ cluster_issuer_acme_route53_service_account_name }}"
namespace: cert-manager
- name: Allow cert-manager to request Route53 ServiceAccount tokens
run_once: true
when: cluster_issuer_acme_route53_auth == "kubernetes"
kubernetes.core.k8s:
state: present
definition:
- apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: "{{ cluster_issuer_name }}"
spec:
acme:
email: "{{ cluster_issuer_acme_email }}"
server: "{{ cluster_issuer_acme_server }}"
privateKeySecretRef:
name: "{{ cluster_issuer_acme_private_key_secret_name }}"
solvers:
- dns01:
route53:
region: "{{ cluster_issuer_acme_route53_region }}"
hostedZoneID: "{{ cluster_issuer_acme_route53_hosted_zone_id }}"
accessKeyID: "{{ cluster_issuer_acme_route53_access_key_id }}"
secretAccessKeySecretRef:
name: "{{ cluster_issuer_acme_route53_secret_name }}"
key: secret-access-key
name: "{{ cluster_issuer_acme_route53_service_account_name }}-tokenrequest"
namespace: cert-manager
rules:
- apiGroups:
- ""
resources:
- serviceaccounts/token
resourceNames:
- "{{ cluster_issuer_acme_route53_service_account_name }}"
verbs:
- create
- apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: "{{ cluster_issuer_acme_route53_service_account_name }}-tokenrequest"
namespace: cert-manager
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: "{{ cluster_issuer_acme_route53_service_account_name }}-tokenrequest"
subjects:
- kind: ServiceAccount
name: cert-manager
namespace: cert-manager
- name: Create ClusterIssuer
run_once: true
vars:
_route53_common:
region: "{{ cluster_issuer_acme_route53_region }}"
hostedZoneID: "{{ cluster_issuer_acme_route53_hosted_zone_id }}"
_route53_role_arn: "{{ cluster_issuer_acme_route53_role_arn | default('') }}"
_route53_role: "{{ {'role': _route53_role_arn} if _route53_role_arn else {} }}"
_route53_static:
accessKeyID: "{{ cluster_issuer_acme_route53_access_key_id | default('') }}"
secretAccessKeySecretRef:
name: "{{ cluster_issuer_acme_route53_secret_name }}"
key: secret-access-key
_route53_kubernetes:
auth:
kubernetes:
serviceAccountRef:
name: "{{ cluster_issuer_acme_route53_service_account_name }}"
_route53_auth: >-
{{
_route53_static if cluster_issuer_acme_route53_auth == "static"
else (_route53_kubernetes if cluster_issuer_acme_route53_auth == "kubernetes"
else {})
}}
kubernetes.core.k8s:
state: present
definition:
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: "{{ cluster_issuer_name }}"
spec:
acme:
email: "{{ cluster_issuer_acme_email }}"
server: "{{ cluster_issuer_acme_server }}"
privateKeySecretRef:
name: "{{ cluster_issuer_acme_private_key_secret_name }}"
solvers:
- dns01:
route53: "{{ _route53_common | combine(_route53_role) | combine(_route53_auth) }}"