Skip to content

Commit

Permalink
Add root readonly attribute to authorities (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
areed authored Dec 12, 2023
1 parent 5bb5491 commit ffa3e4e
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 26 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/authority.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ output "bootstrap_preexisting" {
- `domain` (String) The domain where the authority can be reached.
- `fingerprint` (String) The SHA-256 digest of the authority's root certificate in hex format.
- `name` (String) The name of the authority.
- `root` (String) The root certificate in pem format.
- `type` (String) One of the available authority types
Allowed values: `devops` `advanced` `managed`

Expand Down
1 change: 1 addition & 0 deletions docs/resources/authority.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ resource "smallstep_authority" "advanced" {
- `domain` (String) The domain where the authority can be reached.
- `fingerprint` (String) The SHA-256 digest of the authority's root certificate in hex format.
- `id` (String) A UUID identifying this authority.
- `root` (String) The root certificate in pem format.

<a id="nestedatt--intermediate_issuer"></a>
### Nested Schema for `intermediate_issuer`
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/deepmap/oapi-codegen v1.12.4
github.com/getkin/kin-openapi v0.107.0
github.com/go-chi/chi/v5 v5.0.7
github.com/google/uuid v1.3.0
github.com/google/uuid v1.3.1
github.com/hashicorp/terraform-plugin-docs v0.14.1
github.com/hashicorp/terraform-plugin-framework v1.2.0
github.com/hashicorp/terraform-plugin-go v0.15.0
Expand Down Expand Up @@ -75,15 +75,15 @@ require (
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.13.1 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231211222908-989df2bf70f3 // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
34 changes: 17 additions & 17 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
Expand Down Expand Up @@ -253,8 +253,8 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
Expand All @@ -267,8 +267,8 @@ golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5o
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -293,21 +293,21 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ=
golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
Expand All @@ -316,14 +316,14 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A=
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU=
google.golang.org/grpc v1.55.0 h1:3Oj82/tFSCeUrRTg/5E/7d/W5A1tj6Ky1ABAuZuv5ag=
google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231211222908-989df2bf70f3 h1:kzJAXnzZoFbe5bhZd4zjUuHos/I31yH4thfMb/13oVY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231211222908-989df2bf70f3/go.mod h1:eJVxU6o+4G1PSczBr85xmyvSNYAKvAYgkub40YGomFM=
google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk=
google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
5 changes: 5 additions & 0 deletions internal/provider/authority/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (a *DataSource) Read(ctx context.Context, req datasource.ReadRequest, resp
data.Type = types.StringValue(string(authority.Type))
data.Domain = types.StringValue(authority.Domain)
data.Fingerprint = types.StringValue(utils.Deref(authority.Fingerprint))
data.Root = types.StringValue(utils.Deref(authority.Root))
data.CreatedAt = types.StringValue(authority.CreatedAt.Format(time.RFC3339))
data.ActiveRevocation = types.BoolValue(utils.Deref(authority.ActiveRevocation))
var adminEmails []attr.Value
Expand Down Expand Up @@ -147,6 +148,10 @@ func (d *DataSource) Schema(ctx context.Context, req datasource.SchemaRequest, r
MarkdownDescription: properties["fingerprint"],
Computed: true,
},
"root": schema.StringAttribute{
MarkdownDescription: properties["root"],
Computed: true,
},
"created_at": schema.StringAttribute{
MarkdownDescription: properties["createdAt"],
Computed: true,
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/authority/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type DataModel struct {
Type types.String `tfsdk:"type"`
Domain types.String `tfsdk:"domain"`
Fingerprint types.String `tfsdk:"fingerprint"`
Root types.String `tfsdk:"root"`
CreatedAt types.String `tfsdk:"created_at"`
ActiveRevocation types.Bool `tfsdk:"active_revocation"`
AdminEmails types.Set `tfsdk:"admin_emails"`
Expand All @@ -29,6 +30,7 @@ type ResourceModel struct {
Subdomain types.String `tfsdk:"subdomain"`
Domain types.String `tfsdk:"domain"`
Fingerprint types.String `tfsdk:"fingerprint"`
Root types.String `tfsdk:"root"`
CreatedAt types.String `tfsdk:"created_at"`
ActiveRevocation types.Bool `tfsdk:"active_revocation"`
AdminEmails types.Set `tfsdk:"admin_emails"`
Expand Down
11 changes: 10 additions & 1 deletion internal/provider/authority/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ func (r *Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp
MarkdownDescription: properties["fingerprint"],
Computed: true,
},
"root": schema.StringAttribute{
MarkdownDescription: properties["root"],
Computed: true,
},
"created_at": schema.StringAttribute{
MarkdownDescription: properties["createdAt"],
Computed: true,
Expand Down Expand Up @@ -352,6 +356,7 @@ func (a *Resource) Create(ctx context.Context, req resource.CreateRequest, resp
data.ID = types.StringValue(authority.Id)
data.Domain = types.StringValue(authority.Domain)
data.Fingerprint = types.StringValue(utils.Deref(authority.Fingerprint))
data.Root = types.StringValue(utils.Deref(authority.Root))
data.CreatedAt = types.StringValue(authority.CreatedAt.Format(time.RFC3339))

tflog.Trace(ctx, fmt.Sprintf("create authority %q resource", data.ID.ValueString()))
Expand Down Expand Up @@ -406,6 +411,7 @@ func (a *Resource) Read(ctx context.Context, req resource.ReadRequest, resp *res
data.Type = types.StringValue(string(authority.Type))
data.Domain = types.StringValue(authority.Domain)
data.Fingerprint = types.StringValue(utils.Deref(authority.Fingerprint))
data.Root = types.StringValue(utils.Deref(authority.Root))
data.CreatedAt = types.StringValue(authority.CreatedAt.Format(time.RFC3339))

activeRevocation, diags := utils.ToOptionalBool(ctx, authority.ActiveRevocation, req.State, path.Root("active_revocation"))
Expand Down Expand Up @@ -434,7 +440,10 @@ func (a *Resource) Read(ctx context.Context, req resource.ReadRequest, resp *res
}

func (r *Resource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
// Update not supported. All changes require replacement.
resp.Diagnostics.AddError(
"Update not supported",
"All changes require replacement",
)
}

func (a *Resource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
Expand Down
1 change: 1 addition & 0 deletions internal/provider/authority_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ data "smallstep_authority" "test" {
resource.TestCheckResourceAttr("data.smallstep_authority.test", "domain", authority.Domain),
resource.TestCheckResourceAttr("data.smallstep_authority.test", "created_at", authority.CreatedAt.Format(time.RFC3339)),
resource.TestCheckResourceAttr("data.smallstep_authority.test", "fingerprint", *authority.Fingerprint),
resource.TestCheckResourceAttr("data.smallstep_authority.test", "root", *authority.Root),
resource.TestCheckResourceAttr("data.smallstep_authority.test", "admin_emails.0", (*authority.AdminEmails)[0]),
),
},
Expand Down
1 change: 1 addition & 0 deletions internal/provider/authority_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ resource "smallstep_authority" "devops" {
resource.TestMatchResourceAttr("smallstep_authority.devops", "id", regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)),
resource.TestCheckResourceAttr("smallstep_authority.devops", "domain", devopsSlug+caDomain),
resource.TestMatchResourceAttr("smallstep_authority.devops", "fingerprint", regexp.MustCompile(`^[0-9a-z]{64}$`)),
resource.TestMatchResourceAttr("smallstep_authority.devops", "root", regexp.MustCompile(`-----BEGIN`)),
resource.TestMatchResourceAttr("smallstep_authority.devops", "created_at", regexp.MustCompile(`^20\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ`)),
),
},
Expand Down

0 comments on commit ffa3e4e

Please sign in to comment.