Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
Add azure_environment option to config
Browse files Browse the repository at this point in the history
to allow switching between Commercial and GCC-H Azure environments
  • Loading branch information
ebarrere committed Apr 23, 2024
1 parent 622bd4f commit b33d65e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions internal/aad/aad.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
)

const (
endpoint = "https://login.microsoftonline.com"

invalidCredCode = 50126
requiresMFACode = 50076
noSuchUserCode = 50034
Expand All @@ -25,6 +23,8 @@ const (
)

var (
endpoint = "https://login.microsoftonline.com"

// ErrNoNetwork is returned in case of no network available.
ErrNoNetwork = errors.New("NO NETWORK")
// ErrDeny is returned in case of denial returned by AAD.
Expand All @@ -46,6 +46,9 @@ type AAD struct {

// Authenticate tries to authenticate username against AAD.
func (auth AAD) Authenticate(ctx context.Context, cfg config.AAD, username, password string) error {
if cfg.AzureEnvironment == "GCC-H" {
endpoint = "https://login.microsoftonline.us"
}
authority := fmt.Sprintf("%s/%s", endpoint, cfg.TenantID)
logger.Debug(ctx, "Connecting to %q, with clientID %q for user %q", authority, cfg.AppID, username)

Expand Down Expand Up @@ -104,7 +107,7 @@ func (auth AAD) Authenticate(ctx context.Context, cfg config.AAD, username, pass

logger.Debug(ctx, "For more information about the error code(s), see:")
for _, errcode := range addErrWithCodes.ErrorCodes {
logger.Debug(ctx, "- Error code %d: https://login.microsoftonline.com/error?code=%d", errcode, errcode)
logger.Debug(ctx, "- Error code %d: %s/error?code=%d", errcode, endpoint, errcode)
}

return ErrDeny
Expand Down
4 changes: 4 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
type AAD struct {
TenantID string `ini:"tenant_id"`
AppID string `ini:"app_id"`
AzureEnvironment string `ini:"azure_environment"`
OfflineCredentialsExpiration *int `ini:"offline_credentials_expiration"`
HomeDirPattern string `ini:"homedir"`
Shell string `ini:"shell"`
Expand Down Expand Up @@ -93,6 +94,9 @@ func Load(ctx context.Context, p, domain string, opts ...Option) (config AAD, er
if config.AppID == "" {
return AAD{}, fmt.Errorf("missing required 'app_id' entry in configuration file")
}
if config.AzureEnvironment == "" {
config.AzureEnvironment = "Commercial"
}

return config, nil
}
Expand Down

0 comments on commit b33d65e

Please sign in to comment.