Skip to content

Commit bbeb677

Browse files
Encode b64_mac_key in base64url, not in base64 (#13033) (#9424)
[upstream:d7efb7266051a333f248d3bbc7f103dc582a45e7] Signed-off-by: Modular Magician <[email protected]>
1 parent dd1fb72 commit bbeb677

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

Diff for: .changelog/13033.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
publicca: encode b64_mac_key in base64url, not in base64
3+
```

Diff for: google-beta/services/publicca/resource_public_ca_external_account_key.go

+26-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package publicca
2121

2222
import (
23+
"encoding/base64"
2324
"fmt"
2425
"log"
2526
"net/http"
@@ -56,10 +57,18 @@ func ResourcePublicCAExternalAccountKey() *schema.Resource {
5657
Default: "global",
5758
},
5859
"b64_mac_key": {
60+
Type: schema.TypeString,
61+
Computed: true,
62+
Deprecated: "`b64_mac_key` is deprecated and will be removed in a future major release. Use `b64url_mac_key` instead.",
63+
Description: `Base64-URL-encoded HS256 key. It is generated by the PublicCertificateAuthorityService
64+
when the ExternalAccountKey is created.`,
65+
Sensitive: true,
66+
},
67+
"b64url_mac_key": {
5968
Type: schema.TypeString,
6069
Computed: true,
6170
Description: `Base64-URL-encoded HS256 key. It is generated by the PublicCertificateAuthorityService
62-
when the ExternalAccountKey is created.`,
71+
when the ExternalAccountKey is created.'`,
6372
Sensitive: true,
6473
},
6574
"key_id": {
@@ -135,6 +144,9 @@ func resourcePublicCAExternalAccountKeyCreate(d *schema.ResourceData, meta inter
135144
if err := d.Set("b64_mac_key", flattenPublicCAExternalAccountKeyB64MacKey(res["b64MacKey"], d, config)); err != nil {
136145
return fmt.Errorf(`Error setting computed identity field "b64_mac_key": %s`, err)
137146
}
147+
if err := d.Set("b64url_mac_key", flattenPublicCAExternalAccountKeyB64urlMacKey(res["b64MacKey"], d, config)); err != nil {
148+
return fmt.Errorf(`Error setting computed identity field "b64url_mac_key": %s`, err)
149+
}
138150

139151
// Store the ID now
140152
id, err := tpgresource.ReplaceVars(d, config, "{{name}}")
@@ -173,3 +185,16 @@ func flattenPublicCAExternalAccountKeyKeyId(v interface{}, d *schema.ResourceDat
173185
func flattenPublicCAExternalAccountKeyB64MacKey(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
174186
return v
175187
}
188+
189+
func flattenPublicCAExternalAccountKeyB64urlMacKey(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
190+
if v == nil {
191+
return ""
192+
}
193+
194+
dec, err := base64.StdEncoding.DecodeString(v.(string))
195+
if err != nil {
196+
return ""
197+
}
198+
199+
return base64.URLEncoding.EncodeToString(dec)
200+
}

Diff for: google-beta/services/publicca/resource_public_ca_external_account_key_generated_meta.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ api_version: 'v1beta1'
66
api_resource_type_kind: 'ExternalAccountKey'
77
fields:
88
- field: 'b64_mac_key'
9+
- field: 'b64url_mac_key'
910
- field: 'key_id'
1011
- field: 'location'
1112
provider_only: true

Diff for: google-beta/verify/validation.go

+8
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ func ValidateBase64String(i interface{}, val string) ([]string, []error) {
339339
return nil, nil
340340
}
341341

342+
func ValidateBase64URLString(i interface{}, val string) ([]string, []error) {
343+
_, err := base64.URLEncoding.DecodeString(i.(string))
344+
if err != nil {
345+
return nil, []error{fmt.Errorf("could not decode %q as a valid base64URL value.", val)}
346+
}
347+
return nil, nil
348+
}
349+
342350
// StringNotInSlice returns a SchemaValidateFunc which tests if the provided value
343351
// is of type string and that it matches none of the element in the invalid slice.
344352
// if ignorecase is true, case is ignored.

Diff for: website/docs/r/public_ca_external_account_key.html.markdown

+9-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The EAB secret is invalidated if you don't use it within 7 days.
3939
The ACME account registered by using an EAB secret has no expiration.
4040

4141
~> **Warning:** All arguments including the following potentially sensitive
42-
values will be stored in the raw state as plain text: `key_id`, `b64_mac_key`.
42+
values will be stored in the raw state as plain text: `key_id`, `b64_mac_key`, `b64url_mac_key`.
4343
[Read more about sensitive data in state](https://www.terraform.io/language/state/sensitive-data).
4444

4545
## Example Usage - Public Ca External Account Key
@@ -82,10 +82,18 @@ In addition to the arguments listed above, the following computed attributes are
8282
**Note**: This property is sensitive and will not be displayed in the plan.
8383

8484
* `b64_mac_key` -
85+
(Deprecated)
8586
Base64-URL-encoded HS256 key. It is generated by the PublicCertificateAuthorityService
8687
when the ExternalAccountKey is created.
8788
**Note**: This property is sensitive and will not be displayed in the plan.
8889

90+
~> **Warning:** `b64_mac_key` is deprecated and will be removed in a future major release. Use `b64url_mac_key` instead.
91+
92+
* `b64url_mac_key` -
93+
Base64-URL-encoded HS256 key. It is generated by the PublicCertificateAuthorityService
94+
when the ExternalAccountKey is created.'
95+
**Note**: This property is sensitive and will not be displayed in the plan.
96+
8997

9098
## Timeouts
9199

0 commit comments

Comments
 (0)