Skip to content

Commit a8171af

Browse files
committed
Add sv command to support service accounts
1 parent b65d679 commit a8171af

File tree

7 files changed

+245
-2
lines changed

7 files changed

+245
-2
lines changed

cmd/admin-kms-key-status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ func (s kmsKeyStatusMsg) String() string {
8787

8888
func (s kmsKeyStatusMsg) JSON() string {
8989
const fmtStr = `{"key-id":"%s","encryption-error":"%s","update-error":"%s","decryption-error":"%s"}`
90-
return fmt.Sprintf(fmtStr, s.KeyID, s.EncryptionErr, s.UpdateErr, s.DecryptionErr)
90+
return fmt.Sprintf(fmtStr, s.KeyID, s.EncryptionErr, "", s.DecryptionErr)
9191
}

cmd/admin-user-svc-generate.go

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* MinIO Client (C) 2018 MinIO, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package cmd
18+
19+
import (
20+
"fmt"
21+
"io/ioutil"
22+
23+
"github.com/fatih/color"
24+
"github.com/minio/cli"
25+
json "github.com/minio/mc/pkg/colorjson"
26+
"github.com/minio/mc/pkg/probe"
27+
"github.com/minio/minio/pkg/console"
28+
)
29+
30+
var adminUserSVCGenerateCmd = cli.Command{
31+
Name: "generate",
32+
Usage: "generate a new service account",
33+
Action: mainAdminUserSVCGenerate,
34+
Before: setGlobalsFromContext,
35+
Flags: globalFlags,
36+
CustomHelpTemplate: `NAME:
37+
{{.HelpName}} - {{.Usage}}
38+
39+
USAGE:
40+
{{.HelpName}} TARGET PARENTUSER
41+
42+
PARENTUSER:
43+
The parent user.
44+
45+
FLAGS:
46+
{{range .VisibleFlags}}{{.}}
47+
{{end}}
48+
49+
EXAMPLES:
50+
1. Add a new service account under the name of 'foobar' to MinIO server.
51+
{{.Prompt}} {{.HelpName}} myminio foobar /tmp/file.json
52+
`,
53+
}
54+
55+
func checkAdminUserSVCGenerateSyntax(ctx *cli.Context) {
56+
if len(ctx.Args()) != 3 {
57+
cli.ShowCommandHelpAndExit(ctx, "generate", 1) // last argument is exit code
58+
}
59+
}
60+
61+
// svcMessage container for content message structure
62+
type svcMessage struct {
63+
AccessKey string `json:"accessKey,omitempty"`
64+
SecretKey string `json:"secretKey,omitempty"`
65+
SessionToken string `json:"sessionToken,omitempty"`
66+
}
67+
68+
func (u svcMessage) String() string {
69+
return fmt.Sprintf("Access Key: %s\nSecret Key: %s\nSession Token: %s\n",
70+
u.AccessKey, u.SecretKey, u.SessionToken)
71+
}
72+
73+
func (u svcMessage) JSON() string {
74+
jsonMessageBytes, e := json.MarshalIndent(u, "", " ")
75+
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
76+
77+
return string(jsonMessageBytes)
78+
}
79+
80+
func mainAdminUserSVCGenerate(ctx *cli.Context) error {
81+
checkAdminUserSVCGenerateSyntax(ctx)
82+
83+
console.SetColor("SVCMessage", color.New(color.FgGreen))
84+
85+
// Get the alias parameter from cli
86+
args := ctx.Args()
87+
aliasedURL := args.Get(0)
88+
89+
// Create a new MinIO Admin Client
90+
client, err := newAdminClient(aliasedURL)
91+
fatalIf(err, "Unable to initialize admin connection.")
92+
93+
parentUser := args.Get(1)
94+
policyDoc, e := ioutil.ReadFile(args.Get(2))
95+
fatalIf(probe.NewError(e).Trace(args...), "Cannot load the policy document")
96+
97+
creds, e := client.AddServiceAccount(parentUser, string(policyDoc))
98+
fatalIf(probe.NewError(e).Trace(args...), "Cannot add new service account")
99+
100+
printMsg(svcMessage{
101+
AccessKey: creds.AccessKey,
102+
SecretKey: creds.SecretKey,
103+
SessionToken: creds.SessionToken,
104+
})
105+
106+
return nil
107+
}

cmd/admin-user-svc-show.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* MinIO Client (C) 2020 MinIO, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package cmd
18+
19+
import (
20+
"github.com/fatih/color"
21+
"github.com/minio/cli"
22+
"github.com/minio/mc/pkg/probe"
23+
"github.com/minio/minio/pkg/console"
24+
)
25+
26+
var adminUserSVCShowCmd = cli.Command{
27+
Name: "show",
28+
Usage: "show the credentials of the specified service account",
29+
Action: mainAdminUserSVCShow,
30+
Before: setGlobalsFromContext,
31+
Flags: globalFlags,
32+
CustomHelpTemplate: `NAME:
33+
{{.HelpName}} - {{.Usage}}
34+
35+
USAGE:
36+
{{.HelpName}} TARGET SERVICE-ACCOUNT-ACCESS-KEY
37+
38+
SERVICE-ACCOUNT-ACCESS-KEY:
39+
The access key of the service account.
40+
41+
FLAGS:
42+
{{range .VisibleFlags}}{{.}}
43+
{{end}}
44+
EXAMPLES:
45+
1. Show the credentials of the service account 'SKA762Z7UPIFS5OL1CO4'.
46+
{{.Prompt}} {{.HelpName}} myminio/ SKA762Z7UPIFS5OL1CO4
47+
`,
48+
}
49+
50+
func checkAdminUserSVCShowSyntax(ctx *cli.Context) {
51+
if len(ctx.Args()) != 2 {
52+
cli.ShowCommandHelpAndExit(ctx, "show", 1) // last argument is exit code
53+
}
54+
}
55+
56+
func mainAdminUserSVCShow(ctx *cli.Context) error {
57+
checkAdminUserSVCShowSyntax(ctx)
58+
59+
console.SetColor("SVCMessage", color.New(color.FgGreen))
60+
61+
// Get the alias parameter from cli
62+
args := ctx.Args()
63+
aliasedURL := args.Get(0)
64+
65+
// Create a new MinIO Admin Client
66+
client, err := newAdminClient(aliasedURL)
67+
fatalIf(err, "Unable to initialize admin connection.")
68+
69+
serviceAccountKey := args.Get(1)
70+
71+
creds, e := client.GetServiceAccount(serviceAccountKey)
72+
fatalIf(probe.NewError(e).Trace(args...), "Cannot show the credentials of the specified service account")
73+
74+
printMsg(svcMessage{
75+
AccessKey: creds.AccessKey,
76+
SecretKey: creds.SecretKey,
77+
SessionToken: creds.SessionToken,
78+
})
79+
80+
return nil
81+
}

cmd/admin-user-svc.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* MinIO Client (C) 2018 MinIO, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package cmd
18+
19+
import (
20+
"github.com/minio/cli"
21+
)
22+
23+
var adminUserSVCCmd = cli.Command{
24+
Name: "svc",
25+
Usage: "manage service accounts",
26+
Action: mainAdminUserSVC,
27+
Before: setGlobalsFromContext,
28+
Flags: globalFlags,
29+
Subcommands: []cli.Command{
30+
adminUserSVCGenerateCmd,
31+
adminUserSVCShowCmd,
32+
},
33+
}
34+
35+
func mainAdminUserSVC(ctx *cli.Context) error {
36+
cli.ShowCommandHelp(ctx, ctx.Args().First())
37+
return nil
38+
// Sub-commands like "get", "set" have their own main.
39+
}

cmd/admin-user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var adminUserCmd = cli.Command{
2525
Before: setGlobalsFromContext,
2626
Flags: globalFlags,
2727
Subcommands: []cli.Command{
28+
adminUserSVCCmd,
2829
adminUserAddCmd,
2930
adminUserDisableCmd,
3031
adminUserEnableCmd,

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/mattn/go-isatty v0.0.7
1515
github.com/mattn/go-runewidth v0.0.5 // indirect
1616
github.com/minio/cli v1.22.0
17-
github.com/minio/minio v0.0.0-20200118222113-b849fd7a756d
17+
github.com/minio/minio v0.0.0-20200303034226-c93157019ffe
1818
github.com/minio/minio-go/v6 v6.0.49-0.20200218155844-112c09f43c78
1919
github.com/minio/sha256-simd v0.1.1
2020
github.com/mitchellh/go-homedir v1.1.0
@@ -33,3 +33,5 @@ require (
3333
gopkg.in/ini.v1 v1.52.0 // indirect
3434
gopkg.in/yaml.v2 v2.2.4
3535
)
36+
37+
replace github.com/minio/minio => /home/vadmeste/work/gospace/src/github.com/minio/minio/

go.sum

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
33
cloud.google.com/go v0.39.0/go.mod h1:rVLT6fkc8chs9sfPtFc1SBH6em7n+ZoXaG+87tDISts=
44
contrib.go.opencensus.io/exporter/ocagent v0.5.0/go.mod h1:ImxhfLRpxoYiSq891pBrLVhN+qmP8BTVvdH2YLs7Gl0=
55
git.apache.org/thrift.git v0.12.0/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
6+
git.apache.org/thrift.git v0.13.0/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
67
github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4=
78
github.com/Azure/azure-storage-blob-go v0.8.0/go.mod h1:lPI3aLPpuLTeUwh1sViKXFxwl2B6teiRqI0deQUvsw0=
89
github.com/Azure/go-autorest v11.7.1+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
@@ -65,9 +66,11 @@ github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga
6566
github.com/fortytw2/leaktest v1.2.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
6667
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
6768
github.com/frankban/quicktest v1.4.1/go.mod h1:36zfPVQyHxymz4cH7wlDmVwDrJuljRB60qkgn7rorfQ=
69+
github.com/frankban/quicktest v1.7.2/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o=
6870
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
6971
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 h1:Mn26/9ZMNWSw9C9ERFA1PUxfmGpolnw2v0bKOREu5ew=
7072
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I=
73+
github.com/go-ini/ini v1.52.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
7174
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
7275
github.com/go-ldap/ldap v3.0.2+incompatible/go.mod h1:qfd9rJvER9Q0/D/Sqn1DfHRoBp40uXYvFoEVrNEPqRc=
7376
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
@@ -155,6 +158,7 @@ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht
155158
github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo=
156159
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
157160
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
161+
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
158162
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
159163
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
160164
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
@@ -164,6 +168,7 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
164168
github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
165169
github.com/klauspost/compress v1.9.4/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
166170
github.com/klauspost/compress v1.9.7/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
171+
github.com/klauspost/compress v1.9.8/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
167172
github.com/klauspost/cpuid v1.2.2/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
168173
github.com/klauspost/pgzip v1.2.1/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
169174
github.com/klauspost/readahead v1.3.1/go.mod h1:AH9juHzNH7xqdqFHrMRSHeH2Ps+vFf+kblDqzPFiLJg=
@@ -202,13 +207,20 @@ github.com/minio/highwayhash v1.0.0/go.mod h1:xQboMTeM9nY9v/LlAOxFctujiv5+Aq2hR5
202207
github.com/minio/lsync v1.0.1/go.mod h1:tCFzfo0dlvdGl70IT4IAK/5Wtgb0/BrTmo/jE8pArKA=
203208
github.com/minio/minio v0.0.0-20200118222113-b849fd7a756d h1:/i9HncNqZaHhRLwaReYT73wpU1XFiKYIfhwCQOrVcRg=
204209
github.com/minio/minio v0.0.0-20200118222113-b849fd7a756d/go.mod h1:f8MCueGjpibyBY0iVthLZPcrz310Dgwe/Knx+Dx/2+A=
210+
github.com/minio/minio v0.0.0-20200303034226-c93157019ffe h1:RZbdCyyf9TFNDpv5/o3IWdtaxyJ/qoMfj+hFrIL7iRM=
211+
github.com/minio/minio v0.0.0-20200303034226-c93157019ffe/go.mod h1:tXG8W3rZqJBux3Vr3EmQHoGevChHYa3BQ0SGL+B7/5E=
212+
github.com/minio/minio-go v6.0.14+incompatible h1:fnV+GD28LeqdN6vT2XdGKW8Qe/IfjJDswNVuni6km9o=
213+
github.com/minio/minio-go v6.0.14+incompatible/go.mod h1:7guKYtitv8dktvNUGrhzmNlA5wrAABTQXCoesZdFQO8=
205214
github.com/minio/minio-go/v6 v6.0.44/go.mod h1:qD0lajrGW49lKZLtXKtCB4X/qkMf0a5tBvN2PaZg7Gg=
206215
github.com/minio/minio-go/v6 v6.0.45-0.20200117140906-66cf57d21ba4/go.mod h1:qD0lajrGW49lKZLtXKtCB4X/qkMf0a5tBvN2PaZg7Gg=
216+
github.com/minio/minio-go/v6 v6.0.45/go.mod h1:qD0lajrGW49lKZLtXKtCB4X/qkMf0a5tBvN2PaZg7Gg=
207217
github.com/minio/minio-go/v6 v6.0.49-0.20200218155844-112c09f43c78 h1:rGiqpjReCifELAwekJF3istDiHtW3jQYWaR/tbtRfAU=
208218
github.com/minio/minio-go/v6 v6.0.49-0.20200218155844-112c09f43c78/go.mod h1:qD0lajrGW49lKZLtXKtCB4X/qkMf0a5tBvN2PaZg7Gg=
209219
github.com/minio/parquet-go v0.0.0-20191231003236-20b3c07bcd2c/go.mod h1:sl82d+TnCE7qeaNJazHdNoG9Gpyl9SZYfleDAQWrsls=
220+
github.com/minio/parquet-go v0.0.0-20200125064549-a1e49702e174/go.mod h1:PXYM9yI2l0YPmxHUXe6mFTmkQcyaVasDshAPTbGpDoo=
210221
github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU=
211222
github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
223+
github.com/minio/simdjson-go v0.1.3/go.mod h1:iqktgh3PvDlFrP1EUGcb3vjtKspafYfkQm1zofDuw8A=
212224
github.com/minio/sio v0.2.0/go.mod h1:nKM5GIWSrqbOZp0uhyj6M1iA0X6xQzSGtYSaTKSCut0=
213225
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
214226
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
@@ -246,6 +258,7 @@ github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144T
246258
github.com/pborman/getopt v0.0.0-20180729010549-6fdd0a2c7117/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o=
247259
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
248260
github.com/pierrec/lz4 v2.2.6+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
261+
github.com/pierrec/lz4 v2.4.0+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
249262
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
250263
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
251264
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

0 commit comments

Comments
 (0)