Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 8924d24

Browse files
committed
cli/iamcreate: limit name prefix length
1 parent 44d829b commit 8924d24

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

.github/actions/e2e_test/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ runs:
258258
run: |
259259
uuid=$(uuidgen | tr "[:upper:]" "[:lower:]")
260260
uuid=${uuid%%-*}
261+
262+
# GCP has a 6 character limit the additional uuid prefix since the full prefix length has a maximum of 24
263+
if [[ ${{ inputs.cloudProvider }} == 'gcp' ]]; then
264+
uuid=${uuid:0:6}
265+
fi
266+
261267
echo "uuid=${uuid}" | tee -a $GITHUB_OUTPUT
262268
echo "prefix=e2e-${{ github.run_id }}-${{ github.run_attempt }}-${uuid}" | tee -a $GITHUB_OUTPUT
263269

cli/internal/cmd/iamcreate.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ var (
2929
regionRegex = regexp.MustCompile(`^\w+-\w+[0-9]$`)
3030
// Source: https://cloud.google.com/resource-manager/reference/rest/v1/projects.
3131
gcpIDRegex = regexp.MustCompile(`^[a-z][-a-z0-9]{4,28}[a-z0-9]$`)
32+
33+
// We currently append 6 characters to the prefix, therefore we remove 6 characters from the gcpIDRegex.
34+
gcpPrefixRegex = regexp.MustCompile(`^[a-z][-a-z0-9]{4,22}[a-z0-9]$`)
3235
)
3336

3437
// newIAMCreateCmd returns a new cobra.Command for the iam create parent command. It needs another verb, and does nothing on its own.

cli/internal/cmd/iamcreategcp.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ func (f *gcpIAMCreateFlags) parse(flags *pflag.FlagSet) error {
106106
if err != nil {
107107
return fmt.Errorf("getting 'prefix' flag: %w", err)
108108
}
109+
if f.namePrefix != "" && !gcpPrefixRegex.MatchString(f.namePrefix) {
110+
return fmt.Errorf("prefix %q doesn't match %s", f.namePrefix, gcpIDRegex)
111+
}
112+
109113
return nil
110114
}
111115

0 commit comments

Comments
 (0)