-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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="" ```
- Loading branch information
Showing
36 changed files
with
2,275 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// This file is part of MinIO Console Server | ||
// Copyright (c) 2020 MinIO, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package auth | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/minio/mcs/pkg/auth/idp/oauth2" | ||
) | ||
|
||
// IdentityProviderClient interface with all functions to be implemented | ||
// by mock when testing, it should include all IdentityProviderClient respective api calls | ||
// that are used within this project. | ||
type IdentityProviderClient interface { | ||
VerifyIdentity(ctx context.Context, code, state string) (*oauth2.User, error) | ||
GenerateLoginURL() string | ||
} | ||
|
||
// Interface implementation | ||
// | ||
// Define the structure of a IdentityProvider Client and define the functions that are actually used | ||
// during the authentication flow. | ||
type IdentityProvider struct { | ||
Client IdentityProviderClient | ||
} | ||
|
||
// VerifyIdentity will verify the user identity against the idp using the authorization code flow | ||
func (c IdentityProvider) VerifyIdentity(ctx context.Context, code, state string) (*oauth2.User, error) { | ||
return c.Client.VerifyIdentity(ctx, code, state) | ||
} | ||
|
||
// GenerateLoginURL returns a new URL used by the user to login against the idp | ||
func (c IdentityProvider) GenerateLoginURL() string { | ||
return c.Client.GenerateLoginURL() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// This file is part of MinIO Console Server | ||
// Copyright (c) 2020 MinIO, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
// Package oauth2 contains all the necessary configurations to initialize the | ||
// idp communication using oauth2 protocol | ||
package oauth2 | ||
|
||
import ( | ||
"github.com/minio/mcs/pkg/auth/utils" | ||
"github.com/minio/minio/pkg/env" | ||
) | ||
|
||
func GetIdpURL() string { | ||
return env.Get(McsIdpURL, "") | ||
} | ||
|
||
func GetIdpClientID() string { | ||
return env.Get(McsIdpClientID, "") | ||
} | ||
|
||
func GetIdpSecret() string { | ||
return env.Get(McsIdpSecret, "") | ||
} | ||
|
||
// Public endpoint used by the identity oidcProvider when redirecting the user after identity verification | ||
func GetIdpCallbackURL() string { | ||
return env.Get(McsIdpCallbackURL, "") | ||
} | ||
|
||
func GetIdpAdminRoles() string { | ||
return env.Get(McsIdpAdminRoles, "") | ||
} | ||
|
||
func IsIdpEnabled() bool { | ||
return GetIdpURL() != "" && | ||
GetIdpClientID() != "" && | ||
GetIdpSecret() != "" && | ||
GetIdpCallbackURL() != "" | ||
} | ||
|
||
var defaultPassphraseForIdpHmac = utils.RandomCharString(64) | ||
|
||
// GetPassphraseForIdpHmac returns passphrase for the pbkdf2 function used to sign the oauth2 state parameter | ||
func getPassphraseForIdpHmac() string { | ||
return env.Get(McsIdpHmacPassphrase, defaultPassphraseForIdpHmac) | ||
} | ||
|
||
var defaultSaltForIdpHmac = utils.RandomCharString(64) | ||
|
||
// GetSaltForIdpHmac returns salt for the pbkdf2 function used to sign the oauth2 state parameter | ||
func getSaltForIdpHmac() string { | ||
return env.Get(McsIdpHmacSalt, defaultSaltForIdpHmac) | ||
} | ||
|
||
// GetSaltForIdpHmac returns the policy to be assigned to the users authenticating via an IDP | ||
func GetIDPPolicyForUser() string { | ||
return env.Get(McsIdpPolicyUser, "mcsAdmin") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// This file is part of MinIO Console Server | ||
// Copyright (c) 2020 MinIO, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package oauth2 | ||
|
||
const ( | ||
// const for idp configuration | ||
McsIdpURL = "MCS_IDP_URL" | ||
McsIdpClientID = "MCS_IDP_CLIENT_ID" | ||
McsIdpSecret = "MCS_IDP_SECRET" | ||
McsIdpCallbackURL = "MCS_IDP_CALLBACK" | ||
McsIdpAdminRoles = "MCS_IDP_ADMIN_ROLES" | ||
McsIdpHmacPassphrase = "MCS_IDP_HMAC_PASSPHRASE" | ||
McsIdpHmacSalt = "MCS_IDP_HMAC_SALT" | ||
McsIdpPolicyUser = "MCS_IDP_POLICY_USER" | ||
) |
Oops, something went wrong.