Skip to content

Commit b0a4fb9

Browse files
authored
Add ephemeral resources: kubernetes_token_request_v1, kubernetes_certificate_signing_request_v1 (#2628)
1 parent ec878df commit b0a4fb9

21 files changed

+965
-256
lines changed

.changelog/2628.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
```release-note:enhancement
2+
FEATURES:
3+
* New ephemeral resource: `kubernetes_certificate_signing_request_v1`
4+
* New ephemeral resource: `kubernetes_token_request_v1`
5+
```

.github/workflows/acceptance_tests_aks.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ jobs:
6767
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
6868
run: |
6969
make testacc
70+
make frameworkacc
7071
- name: Destroy AKS
7172
if: always()
7273
working-directory: ${{ github.workspace }}/kubernetes/test-infra/aks

.github/workflows/acceptance_tests_eks.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ jobs:
8585
# More information: https://developer.hashicorp.com/terraform/plugin/sdkv2/testing/acceptance-tests#terraform-cli-installation-behaviors
8686
run: |
8787
make testacc
88+
make frameworkacc
8889
- name: Destroy EKS cluster
8990
if: always() # we should destroy the cluster even if the tests fail
9091
working-directory: ${{ github.workspace }}/kubernetes/test-infra/eks

.github/workflows/acceptance_tests_gke.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ jobs:
8585
# More information: https://developer.hashicorp.com/terraform/plugin/sdkv2/testing/acceptance-tests#terraform-cli-installation-behaviors
8686
run: |
8787
make testacc
88+
make frameworkacc
8889
- name: Destroy GKE cluster
8990
if: always() # we should destroy the cluster even if the tests fail
9091
working-directory: ${{ github.workspace }}/kubernetes/test-infra/gke

.github/workflows/acceptance_tests_kind.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
default: "^TestAcc"
1212
terraformVersion:
1313
description: Terraform version
14-
default: 1.7.5
14+
default: 1.10.0-rc3 # FIXME update this once 1.10 goes out
1515
parallelRuns:
1616
description: The maximum number of tests to run simultaneously
1717
default: 8
@@ -29,7 +29,7 @@ env:
2929
KUBECONFIG: ${{ github.workspace }}/.kube/config
3030
KIND_VERSION: ${{ github.event.inputs.kindVersion || vars.KIND_VERSION || '0.25.0' }}
3131
PARALLEL_RUNS: ${{ github.event.inputs.parallelRuns || vars.PARALLEL_RUNS || '8' }}
32-
TERRAFORM_VERSION: ${{ github.event.inputs.terraformVersion || vars.TERRAFORM_VERSION || '1.9.2' }}
32+
TERRAFORM_VERSION: ${{ github.event.inputs.terraformVersion || vars.TERRAFORM_VERSION || '1.10.0-rc3' }}
3333

3434
jobs:
3535
acceptance_tests_kind:
@@ -71,7 +71,7 @@ jobs:
7171
- name: Install Terraform
7272
uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36 # v3.0.0
7373
with:
74-
terraform_version: ${{ env.TERRAFORM_VERSION }}
74+
# terraform_version: ${{ env.TERRAFORM_VERSION }}
7575
terraform_wrapper: false
7676
- name: Setup kind
7777
uses: helm/kind-action@99576bfa6ddf9a8e612d83b513da5a75875caced # v1.9.0
@@ -90,3 +90,4 @@ jobs:
9090
# More information: https://developer.hashicorp.com/terraform/plugin/sdkv2/testing/acceptance-tests#terraform-cli-installation-behaviors
9191
run: |
9292
make testacc
93+
make frameworkacc

GNUmakefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ OS_ARCH := $(shell go env GOOS)_$(shell go env GOARCH)
88
TF_PROV_DOCS := $(PWD)/kubernetes/test-infra/tfproviderdocs
99

1010
PROVIDER_FUNCTIONS_DIR := "$(PROVIDER_DIR)/internal/framework/provider/functions"
11+
PROVIDER_FRAMEWORK_DIR := "$(PROVIDER_DIR)/internal/framework/provider/..."
1112

1213
ifneq ($(PWD),$(PROVIDER_DIR))
1314
$(error "Makefile must be run from the provider directory")
@@ -77,7 +78,10 @@ testacc: fmtcheck vet
7778
TF_ACC=1 go test $(TEST) -v -vet=off $(TESTARGS) -parallel $(PARALLEL_RUNS) -timeout 3h
7879

7980
testfuncs: fmtcheck
80-
go test $(PROVIDER_FUNCTIONS_DIR) -v -vet=off $(TESTARGS) -parallel $(PARALLEL_RUNS)
81+
go test $(PROVIDER_FUNCTIONS_DIR) -v -vet=off $(TESTARGS) -parallel $(PARALLEL_RUNS)
82+
83+
frameworkacc:
84+
TF_ACC=1 go test $(PROVIDER_FRAMEWORK_DIR) -v -vet=off $(TESTARGS) -parallel $(PARALLEL_RUNS)
8185

8286
test-compile:
8387
@if [ "$(TEST)" = "./..." ]; then \
@@ -175,4 +179,4 @@ docs-lint-fix: tools
175179
@echo "==> Fixing website terraform blocks code with terrafmt..."
176180
@terrafmt fmt ./docs --pattern '*.markdown'
177181

178-
.PHONY: build test testacc tools vet fmt fmtcheck terrafmt test-compile depscheck tests-lint tests-lint-fix docs-lint docs-lint-fix changelog changelog-entry
182+
.PHONY: build test testacc frameworkacc tools vet fmt fmtcheck terrafmt test-compile depscheck tests-lint tests-lint-fix docs-lint docs-lint-fix changelog changelog-entry
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
---
2+
subcategory: "certificates/v1"
3+
page_title: "Kubernetes: kubernetes_certificate_signing_request_v1"
4+
description: |-
5+
Use this resource to generate TLS certificates using Kubernetes.
6+
---
7+
8+
# Ephemeral: kubernetes_certificate_signing_request_v1
9+
10+
Use this resource to generate TLS certificates using Kubernetes. This resource enables automation of [X.509](https://www.itu.int/rec/T-REC-X.509) credential provisioning (including TLS/SSL certificates). It does this by creating a CertificateSigningRequest using the Kubernetes API, which generates a certificate from the Certificate Authority (CA) configured in the Kubernetes cluster. The CSR can be approved automatically by Terraform, or it can be approved by a custom controller running in Kubernetes. See [Kubernetes reference](https://kubernetes.io/docs/reference/access-authn-authz/certificate-signing-requests/) for all available options pertaining to CertificateSigningRequests.
11+
12+
## Schema
13+
14+
### Required
15+
16+
- `metadata` (Block List, Min: 1, Max: 1) Standard certificate signing request's metadata. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata (see [below for nested schema](#nestedblock--metadata))
17+
- `spec` (Block List, Min: 1, Max: 1) CertificateSigningRequest objects provide a mechanism to obtain x509 certificates by submitting a certificate signing request, and having it asynchronously approved and issued.
18+
19+
Kubelets use this API to obtain:
20+
1. client certificates to authenticate to kube-apiserver (with the "kubernetes.io/kube-apiserver-client-kubelet" signerName).
21+
2. serving certificates for TLS endpoints kube-apiserver can connect to securely (with the "kubernetes.io/kubelet-serving" signerName).
22+
23+
This API can be used to request client certificates to authenticate to kube-apiserver (with the "kubernetes.io/kube-apiserver-client" signerName), or to obtain certificates from custom non-Kubernetes signers. (see [below for nested schema](#nestedblock--spec))
24+
25+
### Optional
26+
27+
- `auto_approve` (Boolean) Automatically approve the CertificateSigningRequest
28+
29+
### Read-Only
30+
31+
- `certificate` (String) certificate is populated with an issued certificate by the signer after an Approved condition is present. This field is set via the /status subresource. Once populated, this field is immutable.
32+
33+
If the certificate signing request is denied, a condition of type "Denied" is added and this field remains empty. If the signer cannot issue the certificate, a condition of type "Failed" is added and this field remains empty.
34+
35+
Validation requirements:
36+
1. certificate must contain one or more PEM blocks.
37+
2. All PEM blocks must have the "CERTIFICATE" label, contain no headers, and the encoded data
38+
must be a BER-encoded ASN.1 Certificate structure as described in section 4 of RFC5280.
39+
3. Non-PEM content may appear before or after the "CERTIFICATE" PEM blocks and is unvalidated,
40+
to allow for explanatory text as described in section 5.2 of RFC7468.
41+
42+
If more than one PEM block is present, and the definition of the requested spec.signerName does not indicate otherwise, the first block is the issued certificate, and subsequent blocks should be treated as intermediate certificates and presented in TLS handshakes.
43+
44+
The certificate is encoded in PEM format.
45+
46+
When serialized as JSON or YAML, the data is additionally base64-encoded, so it consists of:
47+
48+
base64(
49+
- `id` (String) The ID of this resource.
50+
51+
<a id="nestedblock--metadata"></a>
52+
### Nested Schema for `metadata`
53+
54+
Optional:
55+
56+
- `name` (String) Name of the certificate signing request, must be unique. Cannot be updated. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
57+
58+
<a id="nestedblock--spec"></a>
59+
### Nested Schema for `spec`
60+
61+
Required:
62+
63+
- `request` (String) request contains an x509 certificate signing request encoded in a "CERTIFICATE REQUEST" PEM block. When serialized as JSON or YAML, the data is additionally base64-encoded.
64+
- `signer_name` (String) signerName indicates the requested signer, and is a qualified name.
65+
66+
List/watch requests for CertificateSigningRequests can filter on this field using a "spec.signerName=NAME" fieldSelector.
67+
68+
Well-known Kubernetes signers are:
69+
1. "kubernetes.io/kube-apiserver-client": issues client certificates that can be used to authenticate to kube-apiserver.
70+
Requests for this signer are never auto-approved by kube-controller-manager, can be issued by the "csrsigning" controller in kube-controller-manager.
71+
2. "kubernetes.io/kube-apiserver-client-kubelet": issues client certificates that kubelets use to authenticate to kube-apiserver.
72+
Requests for this signer can be auto-approved by the "csrapproving" controller in kube-controller-manager, and can be issued by the "csrsigning" controller in kube-controller-manager.
73+
3. "kubernetes.io/kubelet-serving" issues serving certificates that kubelets use to serve TLS endpoints, which kube-apiserver can connect to securely.
74+
Requests for this signer are never auto-approved by kube-controller-manager, and can be issued by the "csrsigning" controller in kube-controller-manager.
75+
76+
More details are available at https://k8s.io/docs/reference/access-authn-authz/certificate-signing-requests/#kubernetes-signers
77+
78+
Custom signerNames can also be specified. The signer defines:
79+
1. Trust distribution: how trust (CA bundles) are distributed.
80+
2. Permitted subjects: and behavior when a disallowed subject is requested.
81+
3. Required, permitted, or forbidden x509 extensions in the request (including whether subjectAltNames are allowed, which types, restrictions on allowed values) and behavior when a disallowed extension is requested.
82+
4. Required, permitted, or forbidden key usages / extended key usages.
83+
5. Expiration/certificate lifetime: whether it is fixed by the signer, configurable by the admin.
84+
6. Whether or not requests for CA certificates are allowed.
85+
86+
Optional:
87+
88+
- `expiration_seconds` (Integer) expirationSeconds is the requested duration of validity of the issued certificate.
89+
90+
The certificate signer may issue a certificate with a different validity duration so a client must check the delta between the notBefore and and notAfter fields in the issued certificate to determine the actual duration. The v1.22+ in-tree implementations of the well-known Kubernetes signers will honor this field as long as the requested duration is not greater than the maximum duration they will honor per the --cluster-signing-duration CLI flag to the Kubernetes controller manager.
91+
92+
Certificate signers may not honor this field for various reasons:
93+
94+
1. Old signer that is unaware of the field (such as the in-tree implementations prior to v1.22)
95+
2. Signer whose configured maximum is shorter than the requested duration
96+
3. Signer whose configured minimum is longer than the requested duration
97+
98+
The minimum valid value for expirationSeconds is 600, i.e. 10 minutes.
99+
100+
- `usages` (Set of String) usages specifies a set of key usages requested in the issued certificate.
101+
102+
Requests for TLS client certificates typically request: "digital signature", "key encipherment", "client auth".
103+
104+
Requests for TLS serving certificates typically request: "key encipherment", "digital signature", "server auth".
105+
106+
Valid values are:
107+
"signing", "digital signature", "content commitment",
108+
"key encipherment", "key agreement", "data encipherment",
109+
"cert sign", "crl sign", "encipher only", "decipher only", "any",
110+
"server auth", "client auth",
111+
"code signing", "email protection", "s/mime",
112+
"ipsec end system", "ipsec tunnel", "ipsec user",
113+
"timestamping", "ocsp signing", "microsoft sgc", "netscape sgc"
114+
115+
116+
## Example Usage
117+
118+
```terraform
119+
ephemeral "kubernetes_certificate_signing_request_v1" "example" {
120+
metadata {
121+
name = "example"
122+
}
123+
spec {
124+
usages = ["client auth", "server auth"]
125+
signer_name = "kubernetes.io/kube-apiserver-client"
126+
127+
request = <<EOT
128+
-----BEGIN CERTIFICATE REQUEST-----
129+
MIHSMIGBAgEAMCoxGDAWBgNVBAoTD2V4YW1wbGUgY2x1c3RlcjEOMAwGA1UEAxMF
130+
YWRtaW4wTjAQBgcqhkjOPQIBBgUrgQQAIQM6AASSG8S2+hQvfMq5ucngPCzK0m0C
131+
ImigHcF787djpF2QDbz3oQ3QsM/I7ftdjB/HHlG2a5YpqjzT0KAAMAoGCCqGSM49
132+
BAMCA0AAMD0CHQDErNLjX86BVfOsYh/A4zmjmGknZpc2u6/coTHqAhxcR41hEU1I
133+
DpNPvh30e0Js8/DYn2YUfu/pQU19
134+
-----END CERTIFICATE REQUEST-----
135+
EOT
136+
}
137+
138+
auto_approve = true
139+
}
140+
```
141+
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
subcategory: "authentication/v1"
3+
page_title: "Kubernetes: kubernetes_token_request_v1"
4+
description: |-
5+
TokenRequest requests a token for a given service account.
6+
---
7+
8+
# Ephemeral: kubernetes_token_request_v1
9+
10+
TokenRequest requests a token for a given service account.
11+
12+
## Schema
13+
14+
### Required
15+
16+
- `metadata` (Block List, Min: 1, Max: 1) Standard token request's metadata. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata (see [below for nested schema](#nestedblock--metadata))
17+
18+
### Optional
19+
20+
- `spec` (Block List, Max: 1) (see [below for nested schema](#nestedblock--spec))
21+
22+
### Read-Only
23+
24+
- `token` (String, Sensitive) Token is the opaque bearer token.
25+
26+
<a id="nestedblock--metadata"></a>
27+
### Nested Schema for `metadata`
28+
29+
Optional:
30+
31+
- `name` (String) Name of the token request, must be unique. Cannot be updated. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
32+
- `namespace` (String) Namespace defines the space within which name of the token request must be unique.
33+
34+
<a id="nestedblock--spec"></a>
35+
### Nested Schema for `spec`
36+
37+
Optional:
38+
39+
- `audiences` (List of String) Audiences are the intendend audiences of the token. A recipient of a token must identify themself with an identifier in the list of audiences of the token, and otherwise should reject the token. A token issued for multiple audiences may be used to authenticate against any of the audiences listed but implies a high degree of trust between the target audiences.
40+
- `bound_object_ref` (Block List, Max: 1) BoundObjectRef is a reference to an object that the token will be bound to. The token will only be valid for as long as the bound object exists. NOTE: The API server's TokenReview endpoint will validate the BoundObjectRef, but other audiences may not. Keep ExpirationSeconds small if you want prompt revocation. (see [below for nested schema](#nestedblock--spec--bound_object_ref))
41+
- `expiration_seconds` (Number) expiration_seconds is the requested duration of validity of the request. The token issuer may return a token with a different validity duration so a client needs to check the 'expiration' field in a response. The expiration can't be less than 10 minutes.
42+
43+
<a id="nestedblock--spec--bound_object_ref"></a>
44+
### Nested Schema for `spec.bound_object_ref`
45+
46+
Optional:
47+
48+
- `api_version` (String) API version of the referent.
49+
- `kind` (String) Kind of the referent. Valid kinds are 'Pod' and 'Secret'.
50+
- `name` (String) Name of the referent.
51+
- `uid` (String) UID of the referent.
52+
53+
## Example Usage
54+
55+
```terraform
56+
resource "kubernetes_service_account_v1" "test" {
57+
metadata {
58+
name = "test"
59+
}
60+
}
61+
62+
ephemeral "kubernetes_token_request_v1" "test" {
63+
metadata {
64+
name = kubernetes_service_account_v1.test.metadata.0.name
65+
}
66+
spec {
67+
audiences = [
68+
"api",
69+
"vault",
70+
"factors"
71+
]
72+
}
73+
}
74+
```
75+

0 commit comments

Comments
 (0)