Skip to content

Commit 69e2bf1

Browse files
committed
Add azure groups support and oauth2 v2.0
1 parent b794248 commit 69e2bf1

File tree

10 files changed

+353
-129
lines changed

10 files changed

+353
-129
lines changed

docs/docs/configuration/alpha_config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ They may change between releases without notice.
164164
| Field | Type | Description |
165165
| ----- | ---- | ----------- |
166166
| `tenant` | _string_ | Tenant directs to a tenant-specific or common (tenant-independent) endpoint<br/>Default value is 'common' |
167+
| `groupField` | _string_ | GroupField configures the group field to be used when building the group list<br/>Default value is 'id' |
167168

168169
### BitbucketOptions
169170

docs/docs/configuration/auth.md

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,42 @@ Note: The user is checked against the group members list on initial authenticati
7272

7373
### Azure Auth Provider
7474

75-
1. Add an application: go to [https://portal.azure.com](https://portal.azure.com), choose **"Azure Active Directory"** in the left menu, select **"App registrations"** and then click on **"New app registration"**.
76-
2. Pick a name and choose **"Webapp / API"** as application type. Use `https://internal.yourcompany.com` as Sign-on URL. Click **"Create"**.
77-
3. On the **"Settings"** / **"Properties"** page of the app, pick a logo and select **"Multi-tenanted"** if you want to allow users from multiple organizations to access your app. Note down the application ID. Click **"Save"**.
78-
4. On the **"Settings"** / **"Required Permissions"** page of the app, click on **"Windows Azure Active Directory"** and then on **"Access the directory as the signed in user"**. Hit **"Save"** and then then on **"Grant permissions"** (you might need another admin to do this).
79-
5. On the **"Settings"** / **"Reply URLs"** page of the app, add `https://internal.yourcompanycom/oauth2/callback` for each host that you want to protect by the oauth2 proxy. Click **"Save"**.
80-
6. On the **"Settings"** / **"Keys"** page of the app, add a new key and note down the value after hitting **"Save"**.
81-
7. Configure the proxy with
75+
1. Add an application: go to [https://portal.azure.com](https://portal.azure.com), choose **Azure Active Directory**, select
76+
**App registrations** and then click on **New registration**.
77+
2. Pick a name, check the supported account type(singletenant, multitenant, etc). In the **Redirect URI** section create a new
78+
**Web** platform entry for each app that you want to protect by the oauth2 proxy(e.g.
79+
https://internal.yourcompanycom/oauth2/callback). Click **Register**.
80+
3. Next we need to add group read permissions for the app registration, on the **API Permissions** page of the app, click on
81+
**Add a permission**, select **Microsoft Graph**, then select **Application permissions**, then click on **Group** and select
82+
**Group.Read.All**. Hit **Add permissions** and then on **Grant admin consent** (you might need an admin to do this).
83+
4. On the **Certificates & secrets** page of the app, add a new client secret and note down the value after hitting **Add**.
84+
5. Configure the proxy with:
85+
- for V1 Azure Auth endpoint (Azure Active Directory Endpoints - https://login.microsoftonline.com/common/oauth2/authorize)
8286

8387
```
8488
--provider=azure
8589
--client-id=<application ID from step 3>
86-
--client-secret=<value from step 6>
87-
--oidc-issuer-url=https://sts.windows.net/{tenant-id}/
90+
--client-secret=<value from step 5>
91+
--azure_tenant={tenant-id}
92+
--oidc_issuer_url=https://sts.windows.net/{tenant-id}/
8893
```
8994

90-
Note: When using the Azure Auth provider with nginx and the cookie session store you may find the cookie is too large and doesn't get passed through correctly. Increasing the proxy_buffer_size in nginx or implementing the [redis session storage](sessions.md#redis-storage) should resolve this.
95+
- for V2 Azure Auth endpoint (Microsoft Identity Platform Endpoints - https://login.microsoftonline.com/common/oauth2/v2.0/authorize)
96+
```
97+
--provider=azure
98+
--client-id=<application ID from step 3>
99+
--client-secret=<value from step 5>
100+
--azure_tenant={tenant-id}
101+
--oidc_issuer_url=https://login.microsoftonline.com/{tenant-id}/v2.0
102+
```
103+
104+
***Notes***:
105+
- When using v2.0 Azure Auth endpoint (`https://login.microsoftonline.com/{tenant-id}/v2.0`) as `--oidc_issuer_url`, in conjunction
106+
with `--resource` flag, be sure to append `/.default` at the end of the resource name. See
107+
https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-permissions-and-consent#the-default-scope for more details.
108+
- When using the Azure Auth provider with nginx and the cookie session store you may find the cookie is too large and doesn't
109+
get passed through correctly. Increasing the proxy_buffer_size in nginx or implementing the [redis session storage](
110+
sessions.md#redis-storage) should resolve this.
91111

92112
### ADFS Auth Provider
93113

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/oauth2-proxy/oauth2-proxy/v7
33
go 1.18
44

55
require (
6+
github.com/AzureAD/microsoft-authentication-library-for-go v0.4.0
67
github.com/Bose/minisentinel v0.0.0-20200130220412-917c5a9223bb
78
github.com/alicebob/miniredis/v2 v2.13.0
89
github.com/benbjohnson/clock v1.1.1-0.20210213131748-c97fc7b6bee0
@@ -54,6 +55,7 @@ require (
5455
github.com/golang/protobuf v1.4.3 // indirect
5556
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
5657
github.com/hashicorp/hcl v1.0.0 // indirect
58+
github.com/kylelemons/godebug v1.1.0 // indirect
5759
github.com/magiconair/properties v1.8.1 // indirect
5860
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
5961
github.com/nxadm/tail v1.4.4 // indirect

go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
33
cloud.google.com/go v0.38.0 h1:ROfEUZz+Gh5pa62DJWXSaonyu3StP6EA6lPEXPI6mCo=
44
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
55
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
6+
github.com/AzureAD/microsoft-authentication-library-for-go v0.4.0 h1:WVsrXCnHlDDX8ls+tootqRE87/hL9S/g4ewig9RsD/c=
7+
github.com/AzureAD/microsoft-authentication-library-for-go v0.4.0/go.mod h1:Vt9sXTKwMyGcOxSmLDMnGPgqsUg7m8pe215qMLrDXw4=
68
github.com/Bose/minisentinel v0.0.0-20200130220412-917c5a9223bb h1:ZVN4Iat3runWOFLaBCDVU5a9X/XikSRBosye++6gojw=
79
github.com/Bose/minisentinel v0.0.0-20200130220412-917c5a9223bb/go.mod h1:WsAABbY4HQBgd3mGuG4KMNTbHJCPvx9IVBHzysbknss=
810
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
@@ -253,6 +255,8 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
253255
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
254256
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
255257
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
258+
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
259+
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
256260
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
257261
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
258262
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
@@ -282,6 +286,7 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ
282286
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
283287
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
284288
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
289+
github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
285290
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
286291
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
287292
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
@@ -336,6 +341,7 @@ github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0
336341
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
337342
github.com/pierrec/lz4 v2.5.2+incompatible h1:WCjObylUIOlKy/+7Abdn34TLIkXiA4UWUMhxq9m9ZXI=
338343
github.com/pierrec/lz4 v2.5.2+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
344+
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4/go.mod h1:N6UoU20jOqggOuDwUaBQpluzLNDqif3kq9z2wpdYEfQ=
339345
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
340346
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
341347
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -552,6 +558,7 @@ golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4/go.mod h1:h1NjWce9XRLGQEsW7w
552558
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
553559
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
554560
golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
561+
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
555562
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
556563
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
557564
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=

pkg/apis/options/legacy_options.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ type LegacyProvider struct {
475475

476476
KeycloakGroups []string `flag:"keycloak-group" cfg:"keycloak_groups"`
477477
AzureTenant string `flag:"azure-tenant" cfg:"azure_tenant"`
478+
AzureGroupField string `flag:"azure-group-field" cfg:"azure_group_field"`
478479
BitbucketTeam string `flag:"bitbucket-team" cfg:"bitbucket_team"`
479480
BitbucketRepository string `flag:"bitbucket-repository" cfg:"bitbucket_repository"`
480481
GitHubOrg string `flag:"github-org" cfg:"github_org"`
@@ -528,6 +529,7 @@ func legacyProviderFlagSet() *pflag.FlagSet {
528529

529530
flagSet.StringSlice("keycloak-group", []string{}, "restrict logins to members of these groups (may be given multiple times)")
530531
flagSet.String("azure-tenant", "common", "go to a tenant-specific or common (tenant-independent) endpoint.")
532+
flagSet.String("azure-group-field", "", "configures the group field to be used when building the groups list(`id` or `displayName`. Default is `id`) from Microsoft Graph(available only for v2.0 oidc url). Based on this value, the `allowed-group` config values should be adjusted accordingly. If using `id` as group field, `allowed-group` should contains groups IDs, if using `displayName` as group field, `allowed-group` should contains groups name")
531533
flagSet.String("bitbucket-team", "", "restrict logins to members of this team")
532534
flagSet.String("bitbucket-repository", "", "restrict logins to user with access to this repository")
533535
flagSet.String("github-org", "", "restrict logins to members of this organisation")
@@ -657,7 +659,8 @@ func (l *LegacyProvider) convert() (Providers, error) {
657659
// This part is out of the switch section because azure has a default tenant
658660
// that needs to be added from legacy options
659661
provider.AzureConfig = AzureOptions{
660-
Tenant: l.AzureTenant,
662+
Tenant: l.AzureTenant,
663+
GroupField: l.AzureGroupField,
661664
}
662665

663666
switch provider.Type {

pkg/apis/options/providers.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ type AzureOptions struct {
142142
// Tenant directs to a tenant-specific or common (tenant-independent) endpoint
143143
// Default value is 'common'
144144
Tenant string `json:"tenant,omitempty"`
145+
// GroupField configures the group field to be used when building the group list
146+
// Default value is 'id'
147+
GroupField string `json:"groupField,omitempty"`
145148
}
146149

147150
type ADFSOptions struct {

pkg/util/util.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,16 @@ func isHostnameAllowed(hostname, allowedHost string) bool {
149149

150150
return false
151151
}
152+
153+
// RemoveDuplicateStr removes duplicates from a slice of strings.
154+
func RemoveDuplicateStr(strSlice []string) []string {
155+
allKeys := make(map[string]bool)
156+
var list []string
157+
for _, item := range strSlice {
158+
if _, value := allKeys[item]; !value {
159+
allKeys[item] = true
160+
list = append(list, item)
161+
}
162+
}
163+
return list
164+
}

0 commit comments

Comments
 (0)