Skip to content

Commit

Permalink
[entraid] add setup script for offline clusters. (#47863)
Browse files Browse the repository at this point in the history
* [entraid] add setup script for offline clusters.

This PR adds a cli configuration for Entra ID where it's possible to default to system credentials instead of relying on OIDC for authentication in EntraID. OIDC is not always a possibility specially when the cluster is private and not internet acessible.

The UX is the following:

```text

Step 1: Run the Setup Script

1. Open **Azure Cloud Shell** (Bash) using **Google Chrome** or **Safari** for the best compatibility.
2. Upload the setup script using the **Upload** button in the Cloud Shell toolbar.
3. Once uploaded, execute the script by running the following command:
   $ bash entraid.sh

**Important Considerations**:
- You must have **Azure privileged administrator permissions** to complete the integration.
- Ensure you're using the **Bash** environment in Cloud Shell.
- During the script execution, you'll be prompted to run 'az login' to authenticate with Azure. **Teleport** does not store or persist your credentials.
- **Mozilla Firefox** users may experience connectivity issues in Azure Cloud Shell; using Chrome or Safari is recommended.

Once the script completes, type 'continue' to proceed, 'exit' to quit: continue

Step 2: Input Tenant ID and Client ID

With the output of Step 1, please copy and paste the following information:
Enter the Tenant ID: 1056b571-0390-4b08-86c8-2edba8d9ae79
Enter the Client ID: 1056b571-0390-4b08-86c8-2edba8d9ae79

Successfully created EntraID plugin "name".
```

Signed-off-by: Tiago Silva <[email protected]>

* move function to api

* handle code review comments

* Apply suggestions from code review

Co-authored-by: Marco Dinis <[email protected]>

* fix url

* enable group claims

* add godoc

* handle code review comments

* fix gomod

---------

Signed-off-by: Tiago Silva <[email protected]>
Co-authored-by: Marco Dinis <[email protected]>
  • Loading branch information
tigrato and marcoandredinis committed Oct 30, 2024
1 parent 254c4c4 commit 8c8f8a8
Show file tree
Hide file tree
Showing 16 changed files with 534 additions and 20 deletions.
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 @@ -82,6 +82,7 @@ require (
github.com/elastic/go-elasticsearch/v8 v8.13.1
github.com/elimity-com/scim v0.0.0-20240320110924-172bf2aee9c8
github.com/evanphx/json-patch v5.9.0+incompatible
github.com/fatih/color v1.17.0
github.com/fsouza/fake-gcs-server v1.48.0
github.com/fxamacker/cbor/v2 v2.6.0
github.com/ghodss/yaml v1.0.0
Expand Down Expand Up @@ -313,7 +314,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.16.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/form3tech-oss/jwt-go v3.2.5+incompatible // indirect
github.com/fsnotify/fsnotify v1.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1164,8 +1164,8 @@ github.com/fatih/camelcase v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
Expand Down
2 changes: 1 addition & 1 deletion integrations/event-handler/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ require (
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.6.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions integrations/event-handler/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,8 @@ github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d h1:105gxyaGwC
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
Expand Down
2 changes: 1 addition & 1 deletion integrations/terraform/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ require (
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.6.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions integrations/terraform/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,8 @@ github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZM
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
Expand Down
3 changes: 3 additions & 0 deletions lib/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,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)
}

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

0 comments on commit 8c8f8a8

Please sign in to comment.