Skip to content

Commit 4cf7ee7

Browse files
feat(flags): remove deprecated literal secret flags, make stdin explicit (#1697)
STACKITCLI-490
1 parent 6809858 commit 4cf7ee7

27 files changed

Lines changed: 1280 additions & 258 deletions

‎docs/stackit_beta_alb_observability-credentials_add.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ stackit beta alb observability-credentials add [flags]
2222
```
2323
-d, --displayname string Displayname for the credentials
2424
-h, --help Help for "stackit beta alb observability-credentials add"
25-
--password string Password. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). Will be read from stdin when empty.
25+
--password secret Password. Use @<file> to read from a file (example: @./secret.txt), or - to read from stdin (hidden input on a terminal). Literal values are not supported.
2626
-u, --username string Username for the credentials
2727
```
2828

‎docs/stackit_beta_alb_observability-credentials_update.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ stackit beta alb observability-credentials update CREDENTIAL_REF_ARG [flags]
2222
```
2323
-d, --displayname string Displayname for the credentials
2424
-h, --help Help for "stackit beta alb observability-credentials update"
25-
--password string Password. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). Will be read from stdin when empty.
25+
--password secret Password. Use @<file> to read from a file (example: @./secret.txt), or - to read from stdin (hidden input on a terminal). Literal values are not supported.
2626
-u, --username string Username for the credentials
2727
```
2828

‎docs/stackit_beta_cdn_distribution_create.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ stackit beta cdn distribution create [flags]
1919
2020
Create a CDN distribution with an Object Storage backend
2121
$ stackit beta cdn distribution create --bucket --bucket-url https://bucket.example.com \
22-
--bucket-credentials-access-key-id yyyy --bucket-region EU \
22+
--bucket-credentials-access-key-id yyyy --bucket-password - --bucket-region EU \
2323
--regions AF,EU
2424
25-
Create a CDN distribution passing the password via stdin, take care that there's a '\n' at the end of the input'
25+
Create a CDN distribution passing the password via stdin
2626
$ cat secret.txt | stackit beta cdn distribution create -y --project-id xxx \
27-
--bucket --bucket-url https://bucket.example.com --bucket-credentials-access-key-id yyyy --bucket-region EU \
27+
--bucket --bucket-url https://bucket.example.com --bucket-credentials-access-key-id yyyy --bucket-password - --bucket-region EU \
2828
--regions AF,EU
2929
```
3030

@@ -35,7 +35,7 @@ stackit beta cdn distribution create [flags]
3535
--blocked-ips strings Comma-separated list of IPv4 addresses to block (e.g., '10.0.0.8,127.0.0.1')
3636
--bucket Use Object Storage backend
3737
--bucket-credentials-access-key-id string Access Key ID for Object Storage backend
38-
--bucket-password string Bucket-Password. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). Will be read from stdin when empty.
38+
--bucket-password secret Bucket-Password. Use @<file> to read from a file (example: @./secret.txt), or - to read from stdin (hidden input on a terminal). Literal values are not supported.
3939
--bucket-region string Region for Object Storage backend
4040
--bucket-url string Bucket URL for Object Storage backend
4141
--default-cache-duration string ISO8601 duration string for default cache duration (e.g., 'PT1H30M' for 1 hour and 30 minutes)
@@ -45,7 +45,7 @@ stackit beta cdn distribution create [flags]
4545
--http-origin-request-headers strings Origin request headers for HTTP backend in the format 'HeaderName: HeaderValue', repeatable. WARNING: do not store sensitive values in the headers!
4646
--http-origin-url string Origin URL for HTTP backend
4747
--loki Enable Loki log sink for the CDN distribution
48-
--loki-password string Loki-Password. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). Will be read from stdin when empty.
48+
--loki-password secret Loki-Password. Use @<file> to read from a file (example: @./secret.txt), or - to read from stdin (hidden input on a terminal). Literal values are not supported.
4949
--loki-push-url string Push URL for log sink
5050
--loki-username string Username for log sink
5151
--monthly-limit-bytes int Monthly limit in bytes for the CDN distribution

‎docs/stackit_beta_cdn_distribution_update.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ stackit beta cdn distribution update [flags]
2424
--blocked-ips strings Comma-separated list of IPv4 addresses to block (e.g., '10.0.0.8,127.0.0.1')
2525
--bucket Use Object Storage backend
2626
--bucket-credentials-access-key-id string Access Key ID for Object Storage backend
27-
--bucket-password string Bucket-Password. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). Will be read from stdin when empty.
27+
--bucket-password secret Bucket-Password. Use @<file> to read from a file (example: @./secret.txt), or - to read from stdin (hidden input on a terminal). Literal values are not supported.
2828
--bucket-region string Region for Object Storage backend
2929
--bucket-url string Bucket URL for Object Storage backend
3030
--default-cache-duration string ISO8601 duration string for default cache duration (e.g., 'PT1H30M' for 1 hour and 30 minutes)
@@ -34,7 +34,7 @@ stackit beta cdn distribution update [flags]
3434
--http-origin-request-headers strings Origin request headers for HTTP backend in the format 'HeaderName: HeaderValue', repeatable. WARNING: do not store sensitive values in the headers!
3535
--http-origin-url string Origin URL for HTTP backend
3636
--loki Enable Loki log sink for the CDN distribution
37-
--loki-password string Loki-Password. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). Will be read from stdin when empty.
37+
--loki-password secret Loki-Password. Use @<file> to read from a file (example: @./secret.txt), or - to read from stdin (hidden input on a terminal). Literal values are not supported.
3838
--loki-push-url string Push URL for log sink
3939
--loki-username string Username for log sink
4040
--monthly-limit-bytes int Monthly limit in bytes for the CDN distribution

‎docs/stackit_beta_intake_user_create.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ stackit beta intake user create [flags]
1313
### Examples
1414

1515
```
16-
Create a new Intake User with required parameters
17-
$ stackit beta intake user create --display-name intake-user --intake-id xxx --password "SuperSafepass123\!"
16+
Create a new Intake User with required parameters, reading the password from stdin
17+
$ stackit beta intake user create --display-name intake-user --intake-id xxx --password -
1818
1919
Create a new Intake User for the dead-letter queue with labels
20-
$ stackit beta intake user create --display-name dlq-user --intake-id xxx --password "SuperSafepass123\!" --type dead-letter --labels "env=prod"
20+
$ stackit beta intake user create --display-name dlq-user --intake-id xxx --password @./password.txt --type dead-letter --labels "env=prod"
2121
```
2222

2323
### Options
@@ -28,7 +28,7 @@ stackit beta intake user create [flags]
2828
-h, --help Help for "stackit beta intake user create"
2929
--intake-id string The UUID of the Intake to associate the user with
3030
--labels stringToString Labels in key=value format, separated by commas (default [])
31-
--password string Password. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). Will be read from stdin when empty. Must contain lower, upper, number, and special characters (min 12 chars)
31+
--password secret Password. Use @<file> to read from a file (example: @./secret.txt), or - to read from stdin (hidden input on a terminal). Literal values are not supported. Must contain lower, upper, number, and special characters (min 12 chars)
3232
--type string Type of user. One of 'intake' (default) or 'dead-letter' (default "intake")
3333
```
3434

‎docs/stackit_beta_intake_user_update.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ stackit beta intake user update USER_ID [flags]
1717
$ stackit beta intake user update xxx --intake-id yyy --display-name "new-user-name"
1818
1919
Update the password and description for an Intake User
20-
$ stackit beta intake user update xxx --intake-id yyy --password "NewSecret123\!" --description "Updated description"
20+
$ stackit beta intake user update xxx --intake-id yyy --password - --description "Updated description"
2121
```
2222

2323
### Options
@@ -28,7 +28,7 @@ stackit beta intake user update USER_ID [flags]
2828
-h, --help Help for "stackit beta intake user update"
2929
--intake-id string Intake ID
3030
--labels stringToString Labels in key=value format, separated by commas. Example: --labels "key1=value1,key2=value2". (default [])
31-
--password string Password. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). Will be read from stdin when empty. Must contain lower, upper, number, and special characters (min 12 chars)
31+
--password secret Password. Use @<file> to read from a file (example: @./secret.txt), or - to read from stdin (hidden input on a terminal). Literal values are not supported. Must contain lower, upper, number, and special characters (min 12 chars)
3232
--type string Type of user. One of 'intake' or 'dead-letter'
3333
```
3434

‎docs/stackit_load-balancer_observability-credentials_add.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ stackit load-balancer observability-credentials add [flags]
1414

1515
```
1616
Add observability credentials to a load balancer with username "xxx" and display name "yyy". The password is entered using the terminal
17-
$ stackit load-balancer observability-credentials add --username xxx --display-name yyy
17+
$ stackit load-balancer observability-credentials add --username xxx --display-name yyy --password -
1818
1919
Add observability credentials to a load balancer with username "xxx" and display name "yyy", providing the path to a file with the password as flag
2020
$ stackit load-balancer observability-credentials add --username xxx --password @./password.txt --display-name yyy
@@ -25,7 +25,7 @@ stackit load-balancer observability-credentials add [flags]
2525
```
2626
--display-name string Credentials display name
2727
-h, --help Help for "stackit load-balancer observability-credentials add"
28-
--password string Password. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). Will be read from stdin when empty.
28+
--password secret Password. Use @<file> to read from a file (example: @./secret.txt), or - to read from stdin (hidden input on a terminal). Literal values are not supported.
2929
--username string Username
3030
```
3131

‎docs/stackit_load-balancer_observability-credentials_update.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ stackit load-balancer observability-credentials update CREDENTIALS_REF [flags]
1414

1515
```
1616
Update the password and username of observability credentials of Load Balancer with credentials reference "credentials-xxx". The password is entered using the terminal
17-
$ stackit load-balancer observability-credentials update credentials-xxx --username new-username
17+
$ stackit load-balancer observability-credentials update credentials-xxx --username new-username --password -
1818
1919
Update the password of observability credentials of Load Balancer with credentials reference "credentials-xxx", by providing the path to a file with the new password as flag
2020
$ stackit load-balancer observability-credentials update credentials-xxx --password @./new-password.txt
@@ -25,7 +25,7 @@ stackit load-balancer observability-credentials update CREDENTIALS_REF [flags]
2525
```
2626
--display-name string Credentials name
2727
-h, --help Help for "stackit load-balancer observability-credentials update"
28-
--password string Password. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). Will be read from stdin when empty.
28+
--password secret Password. Use @<file> to read from a file (example: @./secret.txt), or - to read from stdin (hidden input on a terminal). Literal values are not supported.
2929
--username string Username
3030
```
3131

‎internal/cmd/beta/alb/observability-credentials/add/add.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
9292
GlobalFlagModel: globalFlags,
9393
Username: flags.FlagToStringPointer(p, cmd, usernameFlag),
9494
Displayname: flags.FlagToStringPointer(p, cmd, displaynameFlag),
95-
Password: flags.SecretFlagToStringPointer(p, cmd, passwordFlag),
9695
}
96+
pw, err := flags.ResolveSecretFlagWithAutoPrompt(p, cmd, passwordFlag) //nolint:staticcheck // Deprecated: preserve automatic prompting until 2027-04 (STACKITCLI-549).
97+
if err != nil {
98+
return nil, err
99+
}
100+
model.Password = pw
97101

98102
p.DebugInputModel(model)
99103
return &model, nil

‎internal/cmd/beta/alb/observability-credentials/add/add_test.go‎

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ package add
22

33
import (
44
"context"
5+
"strings"
56
"testing"
7+
"testing/fstest"
8+
9+
"github.com/spf13/cobra"
610

711
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
812
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
913
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
14+
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
1015

1116
"github.com/google/go-cmp/cmp"
1217
"github.com/google/go-cmp/cmp/cmpopts"
@@ -27,13 +32,15 @@ var (
2732
testPassword = "testpassword"
2833
)
2934

35+
const testPwFile = "pw.txt"
36+
3037
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3138
flagValues := map[string]string{
3239
globalflags.ProjectIdFlag: testProjectId,
3340
globalflags.RegionFlag: testRegion,
3441
usernameFlag: testUsername,
3542
displaynameFlag: testDisplayname,
36-
passwordFlag: testPassword,
43+
passwordFlag: "@" + testPwFile,
3744
}
3845
for _, mod := range mods {
3946
mod(flagValues)
@@ -81,6 +88,7 @@ func fixturePayload(mods ...func(payload *alb.CreateCredentialsPayload)) alb.Cre
8188

8289
func TestParseInput(t *testing.T) {
8390
tests := []struct {
91+
stdin string
8492
description string
8593
argValues []string
8694
flagValues map[string]string
@@ -98,11 +106,47 @@ func TestParseInput(t *testing.T) {
98106
flagValues: map[string]string{},
99107
isValid: false,
100108
},
109+
{
110+
description: "password from explicit stdin",
111+
stdin: "stdin-pw\n",
112+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
113+
flagValues[passwordFlag] = "-"
114+
}),
115+
isValid: true,
116+
expectedModel: fixtureInputModel(func(model *inputModel) {
117+
model.Password = new("stdin-pw")
118+
}),
119+
},
120+
{
121+
// Deprecated compatibility behavior; remove this case when automatic prompting is removed in 2027-04 (STACKITCLI-549).
122+
description: "password from implicit stdin",
123+
stdin: "stdin-pw\n",
124+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
125+
delete(flagValues, passwordFlag)
126+
}),
127+
isValid: true,
128+
expectedModel: fixtureInputModel(func(model *inputModel) {
129+
model.Password = new("stdin-pw")
130+
}),
131+
},
132+
{
133+
description: "literal password rejected",
134+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
135+
flagValues[passwordFlag] = "top-secret"
136+
}),
137+
isValid: false,
138+
},
101139
}
102140

103141
for _, tt := range tests {
104142
t.Run(tt.description, func(t *testing.T) {
105-
testutils.TestParseInput(t, NewCmd, parseInput, tt.expectedModel, tt.argValues, tt.flagValues, tt.isValid)
143+
testutils.TestParseInput(t, func(params *types.CmdParams) *cobra.Command {
144+
params.Fs = fstest.MapFS{
145+
testPwFile: {Data: []byte(testPassword)},
146+
}
147+
params.Printer.StdIn = strings.NewReader(tt.stdin)
148+
return NewCmd(params)
149+
}, parseInput, tt.expectedModel, tt.argValues, tt.flagValues, tt.isValid)
106150
})
107151
}
108152
}

0 commit comments

Comments
 (0)