Skip to content

Commit 44d8e9b

Browse files
authored
idp integration for mcs (#75)
This PR adds support for oidc in mcs, to enable idp authentication you need to pass the following environment variables and restart mcs. ``` MCS_IDP_URL="" MCS_IDP_CLIENT_ID="" MCS_IDP_SECRET="" MCS_IDP_CALLBACK="" ```
1 parent f3d7e61 commit 44d8e9b

36 files changed

+2275
-79
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ assets:
2222

2323
test:
2424
@(go test -race -v github.com/minio/mcs/restapi/...)
25-
@(go test -race -v github.com/minio/mcs/pkg/auth)
25+
@(go test -race -v github.com/minio/mcs/pkg/auth/...)
2626

2727
coverage:
2828
@(go test -v -coverprofile=coverage.out github.com/minio/mcs/restapi/... && go tool cover -html=coverage.out && open coverage.html)

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/minio/mcs
33
go 1.14
44

55
require (
6+
github.com/coreos/go-oidc v2.2.1+incompatible
67
github.com/dgrijalva/jwt-go v3.2.0+incompatible
78
github.com/elazarl/go-bindata-assetfs v1.0.0
89
github.com/go-openapi/errors v0.19.4
@@ -19,9 +20,11 @@ require (
1920
github.com/minio/mc v0.0.0-20200415193718-68b638f2f96c
2021
github.com/minio/minio v0.0.0-20200428222040-c3c3e9087bc1
2122
github.com/minio/minio-go/v6 v6.0.55-0.20200424204115-7506d2996b22
23+
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
2224
github.com/satori/go.uuid v1.2.0
2325
github.com/stretchr/testify v1.5.1
2426
github.com/unrolled/secure v1.0.7
2527
golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6
2628
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
29+
golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a
2730
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY=
6969
github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
7070
github.com/coreos/etcd v3.3.12+incompatible h1:pAWNwdf7QiT1zfaWyqCtNZQWCLByQyA3JrSQyuYAqnQ=
7171
github.com/coreos/etcd v3.3.12+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
72+
github.com/coreos/go-oidc v2.2.1+incompatible h1:mh48q/BqXqgjVHpy2ZY7WnWAbenxRjsz9N1i1YxjHAk=
73+
github.com/coreos/go-oidc v2.2.1+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc=
7274
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
7375
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
7476
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8=
@@ -492,6 +494,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
492494
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
493495
github.com/posener/complete v1.2.2-0.20190702141536-6ffe496ea953 h1:oBvgW8IvwF278gJ3R4hH0gD3ZeJxjwBXVIScRR0dRc8=
494496
github.com/posener/complete v1.2.2-0.20190702141536-6ffe496ea953/go.mod h1:6gapUrK/U1TAN7ciCoNRIdVC5sbdBTUh1DKN0g6uH7E=
497+
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 h1:J9b7z+QKAmPf4YLrFg6oQUotqHQeUNWwkvo7jZp1GLU=
498+
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA=
495499
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
496500
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=
497501
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829 h1:D+CiwcpGTW6pL6bv6KI3KbyEyCKyS+1JWS2h8PNDnGA=

models/login_oauth2_auth_request.go

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/auth/idp.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This file is part of MinIO Console Server
2+
// Copyright (c) 2020 MinIO, Inc.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package auth
18+
19+
import (
20+
"context"
21+
22+
"github.com/minio/mcs/pkg/auth/idp/oauth2"
23+
)
24+
25+
// IdentityProviderClient interface with all functions to be implemented
26+
// by mock when testing, it should include all IdentityProviderClient respective api calls
27+
// that are used within this project.
28+
type IdentityProviderClient interface {
29+
VerifyIdentity(ctx context.Context, code, state string) (*oauth2.User, error)
30+
GenerateLoginURL() string
31+
}
32+
33+
// Interface implementation
34+
//
35+
// Define the structure of a IdentityProvider Client and define the functions that are actually used
36+
// during the authentication flow.
37+
type IdentityProvider struct {
38+
Client IdentityProviderClient
39+
}
40+
41+
// VerifyIdentity will verify the user identity against the idp using the authorization code flow
42+
func (c IdentityProvider) VerifyIdentity(ctx context.Context, code, state string) (*oauth2.User, error) {
43+
return c.Client.VerifyIdentity(ctx, code, state)
44+
}
45+
46+
// GenerateLoginURL returns a new URL used by the user to login against the idp
47+
func (c IdentityProvider) GenerateLoginURL() string {
48+
return c.Client.GenerateLoginURL()
49+
}

pkg/auth/idp/oauth2/config.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// This file is part of MinIO Console Server
2+
// Copyright (c) 2020 MinIO, Inc.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
// Package oauth2 contains all the necessary configurations to initialize the
18+
// idp communication using oauth2 protocol
19+
package oauth2
20+
21+
import (
22+
"github.com/minio/mcs/pkg/auth/utils"
23+
"github.com/minio/minio/pkg/env"
24+
)
25+
26+
func GetIdpURL() string {
27+
return env.Get(McsIdpURL, "")
28+
}
29+
30+
func GetIdpClientID() string {
31+
return env.Get(McsIdpClientID, "")
32+
}
33+
34+
func GetIdpSecret() string {
35+
return env.Get(McsIdpSecret, "")
36+
}
37+
38+
// Public endpoint used by the identity oidcProvider when redirecting the user after identity verification
39+
func GetIdpCallbackURL() string {
40+
return env.Get(McsIdpCallbackURL, "")
41+
}
42+
43+
func GetIdpAdminRoles() string {
44+
return env.Get(McsIdpAdminRoles, "")
45+
}
46+
47+
func IsIdpEnabled() bool {
48+
return GetIdpURL() != "" &&
49+
GetIdpClientID() != "" &&
50+
GetIdpSecret() != "" &&
51+
GetIdpCallbackURL() != ""
52+
}
53+
54+
var defaultPassphraseForIdpHmac = utils.RandomCharString(64)
55+
56+
// GetPassphraseForIdpHmac returns passphrase for the pbkdf2 function used to sign the oauth2 state parameter
57+
func getPassphraseForIdpHmac() string {
58+
return env.Get(McsIdpHmacPassphrase, defaultPassphraseForIdpHmac)
59+
}
60+
61+
var defaultSaltForIdpHmac = utils.RandomCharString(64)
62+
63+
// GetSaltForIdpHmac returns salt for the pbkdf2 function used to sign the oauth2 state parameter
64+
func getSaltForIdpHmac() string {
65+
return env.Get(McsIdpHmacSalt, defaultSaltForIdpHmac)
66+
}
67+
68+
// GetSaltForIdpHmac returns the policy to be assigned to the users authenticating via an IDP
69+
func GetIDPPolicyForUser() string {
70+
return env.Get(McsIdpPolicyUser, "mcsAdmin")
71+
}

pkg/auth/idp/oauth2/const.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This file is part of MinIO Console Server
2+
// Copyright (c) 2020 MinIO, Inc.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package oauth2
18+
19+
const (
20+
// const for idp configuration
21+
McsIdpURL = "MCS_IDP_URL"
22+
McsIdpClientID = "MCS_IDP_CLIENT_ID"
23+
McsIdpSecret = "MCS_IDP_SECRET"
24+
McsIdpCallbackURL = "MCS_IDP_CALLBACK"
25+
McsIdpAdminRoles = "MCS_IDP_ADMIN_ROLES"
26+
McsIdpHmacPassphrase = "MCS_IDP_HMAC_PASSPHRASE"
27+
McsIdpHmacSalt = "MCS_IDP_HMAC_SALT"
28+
McsIdpPolicyUser = "MCS_IDP_POLICY_USER"
29+
)

0 commit comments

Comments
 (0)