Skip to content

Commit e12e6e3

Browse files
committed
Entra External Auth for ADO
1 parent e183843 commit e12e6e3

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

coderd/externalauth/externalauth.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@ func ConvertConfig(instrument *promoauth.Factory, entries []codersdk.ExternalAut
499499
if entry.Type == string(codersdk.EnhancedExternalAuthProviderAzureDevops) {
500500
oauthConfig = &jwtConfig{oc}
501501
}
502+
if entry.Type == string(codersdk.EnhancedExternalAuthProviderAzureDevopsEntra) {
503+
oauthConfig = &jwtConfigEntraV1{oc}
504+
}
502505
if entry.Type == string(codersdk.EnhancedExternalAuthProviderJFrog) {
503506
oauthConfig = &exchangeWithClientSecret{oc}
504507
}
@@ -739,6 +742,11 @@ var staticDefaults = map[codersdk.EnhancedExternalAuthProvider]codersdk.External
739742
Regex: `^(https?://)?dev\.azure\.com(/.*)?$`,
740743
Scopes: []string{"vso.code_write"},
741744
},
745+
codersdk.EnhancedExternalAuthProviderAzureDevopsEntra: {
746+
DisplayName: "Azure DevOps (Entra)",
747+
DisplayIcon: "/icon/azure-devops.svg",
748+
Regex: `^(https?://)?dev\.azure\.com(/.*)?$`,
749+
},
742750
codersdk.EnhancedExternalAuthProviderBitBucketCloud: {
743751
AuthURL: "https://bitbucket.org/site/oauth2/authorize",
744752
TokenURL: "https://bitbucket.org/site/oauth2/access_token",
@@ -811,6 +819,24 @@ func (c *jwtConfig) Exchange(ctx context.Context, code string, opts ...oauth2.Au
811819
)
812820
}
813821

822+
// When authenticating via Entra ID ADO only supports v1 tokens that requires the 'resource' rather than scopes
823+
// When ADO gets support for V2 Entra ID tokens this struct and functions can be removed
824+
type jwtConfigEntraV1 struct {
825+
*oauth2.Config
826+
}
827+
828+
func (c *jwtConfigEntraV1) AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string {
829+
return c.Config.AuthCodeURL(state, append(opts, oauth2.SetAuthURLParam("resource", "499b84ac-1321-427f-aa17-267ca6975798"))...)
830+
}
831+
832+
func (c *jwtConfigEntraV1) Exchange(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error) {
833+
return c.Config.Exchange(ctx, code,
834+
append(opts,
835+
oauth2.SetAuthURLParam("resource", "499b84ac-1321-427f-aa17-267ca6975798"),
836+
)...,
837+
)
838+
}
839+
814840
// exchangeWithClientSecret wraps an OAuth config and adds the client secret
815841
// to the Exchange request as a Bearer header. This is used by JFrog Artifactory.
816842
type exchangeWithClientSecret struct {

codersdk/externalauth.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func (e EnhancedExternalAuthProvider) Git() bool {
2525
EnhancedExternalAuthProviderBitBucketCloud,
2626
EnhancedExternalAuthProviderBitBucketServer,
2727
EnhancedExternalAuthProviderAzureDevops,
28+
EnhancedExternalAuthProviderAzureDevopsEntra,
2829
EnhancedExternalAuthProviderGitea:
2930
return true
3031
default:
@@ -33,9 +34,10 @@ func (e EnhancedExternalAuthProvider) Git() bool {
3334
}
3435

3536
const (
36-
EnhancedExternalAuthProviderAzureDevops EnhancedExternalAuthProvider = "azure-devops"
37-
EnhancedExternalAuthProviderGitHub EnhancedExternalAuthProvider = "github"
38-
EnhancedExternalAuthProviderGitLab EnhancedExternalAuthProvider = "gitlab"
37+
EnhancedExternalAuthProviderAzureDevops EnhancedExternalAuthProvider = "azure-devops"
38+
EnhancedExternalAuthProviderAzureDevopsEntra EnhancedExternalAuthProvider = "azure-devops-entra"
39+
EnhancedExternalAuthProviderGitHub EnhancedExternalAuthProvider = "github"
40+
EnhancedExternalAuthProviderGitLab EnhancedExternalAuthProvider = "gitlab"
3941
// EnhancedExternalAuthProviderBitBucketCloud is the Bitbucket Cloud provider.
4042
// Not to be confused with the self-hosted 'EnhancedExternalAuthProviderBitBucketServer'
4143
EnhancedExternalAuthProviderBitBucketCloud EnhancedExternalAuthProvider = "bitbucket-cloud"

docs/admin/external-auth.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ application. The following providers are supported:
2323
- [GitLab](https://docs.gitlab.com/ee/integration/oauth_provider.html)
2424
- [BitBucket](https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud/)
2525
- [Azure DevOps](https://learn.microsoft.com/en-us/azure/devops/integrate/get-started/authentication/oauth?view=azure-devops)
26+
- [Azure DevOps (via Entra ID)](https://learn.microsoft.com/en-us/entra/architecture/auth-oauth2)
2627

2728
Example callback URL:
2829
`https://coder.example.com/external-auth/primary-github/callback`. Use an
@@ -108,6 +109,21 @@ CODER_EXTERNAL_AUTH_0_AUTH_URL="https://app.vssps.visualstudio.com/oauth2/author
108109
CODER_EXTERNAL_AUTH_0_TOKEN_URL="https://app.vssps.visualstudio.com/oauth2/token"
109110
```
110111

112+
### Azure DevOps (via Entra ID)
113+
114+
Azure DevOps (via Entra ID) requires the following environment variables:
115+
116+
```env
117+
CODER_EXTERNAL_AUTH_0_ID="primary-azure-devops"
118+
CODER_EXTERNAL_AUTH_0_TYPE=azure-devops-entra
119+
CODER_EXTERNAL_AUTH_0_CLIENT_ID=xxxxxx
120+
CODER_EXTERNAL_AUTH_0_CLIENT_SECRET=xxxxxxx
121+
CODER_EXTERNAL_AUTH_0_AUTH_URL="https://login.microsoftonline.com/<TENANT ID>/oauth2/authorize"
122+
CODER_EXTERNAL_AUTH_0_TOKEN_URL="https://login.microsoftonline.com/<TENANT ID>/oauth2/token"
123+
```
124+
125+
> Note: Your app registration in Entra ID requires the `vso.code_write` scope
126+
111127
### GitLab self-managed
112128

113129
GitLab self-managed requires the following environment variables:

site/src/api/typesGenerated.ts

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

0 commit comments

Comments
 (0)