Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[entraid] add setup script for offline clusters. #47863

Merged
merged 9 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions api/utils/entraid/federation_metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2024 Gravitational, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package entraid

import (
"net/url"
"path"
)

// FederationMetadataURL returns the URL for the federation metadata endpoint
func FederationMetadataURL(tenantID, appID string) string {
return (&url.URL{
Scheme: "https",
Host: "login.microsoftonline.com",
Path: path.Join(tenantID, "federationmetadata", "2007-06", "federationmetadata.xml"),
RawQuery: url.Values{
"appid": {appID},
}.Encode(),
}).String()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ require (
github.com/elimity-com/scim v0.0.0-20240320110924-172bf2aee9c8
github.com/envoyproxy/go-control-plane v0.13.0
github.com/evanphx/json-patch v5.9.0+incompatible
github.com/fatih/color v1.17.0
github.com/fsnotify/fsnotify v1.7.0
github.com/fsouza/fake-gcs-server v1.49.3
github.com/fxamacker/cbor/v2 v2.7.0
Expand Down Expand Up @@ -323,7 +324,6 @@ require (
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/camelcase v1.0.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.5 // indirect
Expand Down
3 changes: 3 additions & 0 deletions lib/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ type IntegrationConfAzureOIDC struct {
// When this is true, the integration script will produce
// a cache file necessary for TAG synchronization.
AccessGraphEnabled bool

// SkipOIDCConfiguration is a flag indicating that OIDC configuration should be skipped.
SkipOIDCConfiguration bool
}

// IntegrationConfDeployServiceIAM contains the arguments of
Expand Down
10 changes: 7 additions & 3 deletions lib/integrations/azureoidc/enterprise_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var appRoles = []string{
// - Provides Teleport with OIDC authentication to Azure
// - Is given the permissions to access certain Microsoft Graph API endpoints for this tenant.
// - Provides SSO to the Teleport cluster via SAML.
func SetupEnterpriseApp(ctx context.Context, proxyPublicAddr string, authConnectorName string) (string, string, error) {
func SetupEnterpriseApp(ctx context.Context, proxyPublicAddr string, authConnectorName string, skipOIDCSetup bool) (string, string, error) {
var appID, tenantID string

tenantID, err := getTenantID()
Expand Down Expand Up @@ -120,8 +120,12 @@ func SetupEnterpriseApp(ctx context.Context, proxyPublicAddr string, authConnect
}
}

if err := createFederatedAuthCredential(ctx, graphClient, *app.ID, proxyPublicAddr); err != nil {
return appID, tenantID, trace.Wrap(err, "failed to create an OIDC federated auth credential")
// Skip OIDC setup if requested.
// This is useful for clusters that can't use OIDC because they are not reachable from the public internet.
if !skipOIDCSetup {
if err := createFederatedAuthCredential(ctx, graphClient, *app.ID, proxyPublicAddr); err != nil {
return appID, tenantID, trace.Wrap(err, "failed to create an OIDC federated auth credential")
}
}

acsURL, err := url.Parse(proxyPublicAddr)
Expand Down
3 changes: 3 additions & 0 deletions lib/integrations/azureoidc/provision_sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func setupSSO(ctx context.Context, graphClient *msgraph.Client, appObjectID stri
webApp := &msgraph.WebApplication{}
webApp.RedirectURIs = &uris
app.Web = webApp
securityGroups := new(string)
*securityGroups = "SecurityGroup"
app.GroupMembershipClaims = securityGroups

err = graphClient.UpdateApplication(ctx, appObjectID, app)

Expand Down
14 changes: 11 additions & 3 deletions lib/msgraph/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package msgraph

import (
"encoding/json"
"slices"

"github.com/gravitational/trace"
)
Expand All @@ -34,6 +35,12 @@ type DirectoryObject struct {

type Group struct {
DirectoryObject
GroupTypes []string `json:"groupTypes,omitempty"`
}

func (g *Group) IsOffice365Group() bool {
const office365Group = "Unified"
return slices.Contains(g.GroupTypes, office365Group)
}
Comment on lines +41 to 44
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this being used? I can't find it in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's being used in e


func (g *Group) isGroupMember() {}
Expand All @@ -53,9 +60,10 @@ func (u *User) GetID() *string { return u.ID }
type Application struct {
DirectoryObject

AppID *string `json:"appId,omitempty"`
IdentifierURIs *[]string `json:"identifierUris,omitempty"`
Web *WebApplication `json:"web,omitempty"`
AppID *string `json:"appId,omitempty"`
IdentifierURIs *[]string `json:"identifierUris,omitempty"`
Web *WebApplication `json:"web,omitempty"`
GroupMembershipClaims *string `json:"groupMembershipClaims,omitempty"`
}

type WebApplication struct {
Expand Down
Loading
Loading