Skip to content

Commit 39f6b63

Browse files
authored
Merge pull request #47 from jetstack/service_account_wif_example
Add docs for service account resources
2 parents af8e411 + 6a12e41 commit 39f6b63

File tree

3 files changed

+84
-23
lines changed

3 files changed

+84
-23
lines changed

docs/resources/service_account.md

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,58 @@ resource "tls_private_key" "rsa-key" {
1818
rsa_bits = 4096
1919
}
2020
21-
resource "tlspc_service_account" "sa" {
21+
resource "tlspc_service_account" "agent-credentials" {
2222
name = "k8s-cluster"
2323
owner = resource.tlspc_team.team.id
2424
scopes = ["kubernetes-discovery"]
2525
credential_lifetime = 365
2626
public_key = trimspace(resource.tls_private_key.rsa-key.public_key_pem)
2727
}
28+
29+
resource "kubernetes_secret" "credentials" {
30+
metadata {
31+
name = "agent-credentials"
32+
namespace = "venafi"
33+
}
34+
data = {
35+
"privatekey.pem" = tls_private_key.rsa-key.private_key_pem
36+
}
37+
type = "kubernetes.io/opaque"
38+
}
39+
40+
resource "tlspc_service_account" "wif-issuer" {
41+
name = "test-issuer1"
42+
owner = resource.tlspc_team.team.id
43+
scopes = ["certificate-issuance"]
44+
applications = [resource.tlspc_application.app.id]
45+
jwks_uri = "https://kubernetes/.well-known/jwks.json"
46+
issuer_url = "https://kubernetes.default.svc.cluster.local"
47+
subject = "system:serviceaccount:venafi:application-team-1"
48+
audience = "api.venafi.eu"
49+
}
2850
```
2951

3052
<!-- schema generated by tfplugindocs -->
3153
## Schema
3254

3355
### Required
3456

35-
- `name` (String)
36-
- `owner` (String)
37-
- `scopes` (Set of String)
57+
- `name` (String) The name of the service account
58+
- `owner` (String) ID of the team that owns this service account
59+
- `scopes` (Set of String) A list of scopes that this service account is authorised for. Available options include:
60+
* certificate-issuance
61+
* kubernetes-discovery
3862

3963
### Optional
4064

41-
- `applications` (Set of String)
42-
- `audience` (String)
43-
- `credential_lifetime` (Number)
44-
- `issuer_url` (String)
45-
- `jwks_uri` (String)
46-
- `public_key` (String)
47-
- `subject` (String)
65+
- `applications` (Set of String) List of Applications which this service account is authorised for
66+
- `audience` (String) Audience for a WIF type service account
67+
- `credential_lifetime` (Number) Credential Lifetime in days (required for public_key type service accounts)
68+
- `issuer_url` (String) Issuer URL for a WIF type service account
69+
- `jwks_uri` (String) The JWKS URI for a Workload Identity Federation (WIF) type service account
70+
- `public_key` (String) Public Key
71+
- `subject` (String) Subject for a WIF type service account
4872

4973
### Read-Only
5074

51-
- `id` (String) The ID of this resource.
75+
- `id` (String) The ID of this resource

examples/resources/tlspc_service_account/resource.tf

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,32 @@ resource "tls_private_key" "rsa-key" {
33
rsa_bits = 4096
44
}
55

6-
resource "tlspc_service_account" "sa" {
6+
resource "tlspc_service_account" "agent-credentials" {
77
name = "k8s-cluster"
88
owner = resource.tlspc_team.team.id
99
scopes = ["kubernetes-discovery"]
1010
credential_lifetime = 365
1111
public_key = trimspace(resource.tls_private_key.rsa-key.public_key_pem)
1212
}
13+
14+
resource "kubernetes_secret" "credentials" {
15+
metadata {
16+
name = "agent-credentials"
17+
namespace = "venafi"
18+
}
19+
data = {
20+
"privatekey.pem" = tls_private_key.rsa-key.private_key_pem
21+
}
22+
type = "kubernetes.io/opaque"
23+
}
24+
25+
resource "tlspc_service_account" "wif-issuer" {
26+
name = "test-issuer1"
27+
owner = resource.tlspc_team.team.id
28+
scopes = ["certificate-issuance"]
29+
applications = [resource.tlspc_application.app.id]
30+
jwks_uri = "https://kubernetes/.well-known/jwks.json"
31+
issuer_url = "https://kubernetes.default.svc.cluster.local"
32+
subject = "system:serviceaccount:venafi:application-team-1"
33+
audience = "api.venafi.eu"
34+
}

internal/provider/service_account_resource.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,40 +43,55 @@ func (r *serviceAccountResource) Schema(_ context.Context, _ resource.SchemaRequ
4343
PlanModifiers: []planmodifier.String{
4444
stringplanmodifier.UseStateForUnknown(),
4545
},
46+
MarkdownDescription: "The ID of this resource",
4647
},
4748
"name": schema.StringAttribute{
48-
Required: true,
49+
Required: true,
50+
MarkdownDescription: "The name of the service account",
4951
},
5052
"owner": schema.StringAttribute{
51-
Required: true,
53+
Required: true,
54+
MarkdownDescription: "ID of the team that owns this service account",
5255
},
5356
"scopes": schema.SetAttribute{
5457
Required: true,
5558
ElementType: types.StringType,
59+
MarkdownDescription: `
60+
A list of scopes that this service account is authorised for. Available options include:
61+
* certificate-issuance
62+
* kubernetes-discovery
63+
`,
5664
},
5765
// Agent service account
5866
"public_key": schema.StringAttribute{
59-
Optional: true,
67+
Optional: true,
68+
MarkdownDescription: "Public Key",
6069
},
6170
"credential_lifetime": schema.Int32Attribute{
62-
Optional: true,
71+
Optional: true,
72+
MarkdownDescription: "Credential Lifetime in days (required for public_key type service accounts)",
6373
},
6474
// Issuer service account (jwks)
6575
"jwks_uri": schema.StringAttribute{
66-
Optional: true,
76+
Optional: true,
77+
MarkdownDescription: "The JWKS URI for a Workload Identity Federation (WIF) type service account",
6778
},
6879
"issuer_url": schema.StringAttribute{
69-
Optional: true,
80+
Optional: true,
81+
MarkdownDescription: "Issuer URL for a WIF type service account",
7082
},
7183
"audience": schema.StringAttribute{
72-
Optional: true,
84+
Optional: true,
85+
MarkdownDescription: "Audience for a WIF type service account",
7386
},
7487
"subject": schema.StringAttribute{
75-
Optional: true,
88+
Optional: true,
89+
MarkdownDescription: "Subject for a WIF type service account",
7690
},
7791
"applications": schema.SetAttribute{
78-
Optional: true,
79-
ElementType: types.StringType,
92+
Optional: true,
93+
ElementType: types.StringType,
94+
MarkdownDescription: "List of Applications which this service account is authorised for",
8095
},
8196
},
8297
}

0 commit comments

Comments
 (0)