-
Notifications
You must be signed in to change notification settings - Fork 928
feat: secure and cross-domain subdomain-based proxying #4136
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6d21b37
feat: add --app-hostname flag to coder server
deansheather b8a7a45
chore: add test for subdomain proxy passthrough
deansheather 3b875b2
fixup! chore: add test for subdomain proxy passthrough
deansheather 39e9b6f
chore: reorganize subdomain app handler
deansheather 3a099ba
chore: add authorization check endpoint
deansheather 25b8182
Merge branch 'main' into dean/app-tokens
deansheather e864f27
chore: improve proxy auth tests
deansheather b5d2be3
chore: refactor ExtractAPIKey to accept struct
deansheather d9b404d
feat: end-to-end workspace application authentication
deansheather da5f656
Merge branch 'main' into dean/app-tokens
deansheather 312e0d5
fixup! Merge branch 'main' into dean/app-tokens
deansheather 16bbcbe
feat: use a custom cookie name for devurls to avoid clashes
deansheather a172cd5
feat: /api/v2/applications/host endpoint, PR comments
deansheather d4986d2
fixup! feat: /api/v2/applications/host endpoint, PR comments
deansheather 9b56f02
fixup! feat: /api/v2/applications/host endpoint, PR comments
deansheather d9186a8
chore: more pr comments
deansheather 35962fc
Remove checkUserPermissions
kylecarbs b1436ec
fixup! Remove checkUserPermissions
deansheather 11e985f
Merge branch 'main' into dean/app-tokens
deansheather 496fde3
fixup! Merge branch 'main' into dean/app-tokens
deansheather 3e30a9f
chore: more security stuff
deansheather 11e6061
fixup! chore: more security stuff
deansheather cf70650
chore: more comments
deansheather 6d66f55
Merge branch 'main' into dean/app-tokens
deansheather File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package coderd_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/coder/coder/coderd/coderdtest" | ||
"github.com/coder/coder/coderd/rbac" | ||
"github.com/coder/coder/codersdk" | ||
"github.com/coder/coder/testutil" | ||
) | ||
|
||
func TestCheckPermissions(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) | ||
t.Cleanup(cancel) | ||
|
||
adminClient := coderdtest.New(t, nil) | ||
// Create adminClient, member, and org adminClient | ||
adminUser := coderdtest.CreateFirstUser(t, adminClient) | ||
memberClient := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID) | ||
memberUser, err := memberClient.User(ctx, codersdk.Me) | ||
require.NoError(t, err) | ||
orgAdminClient := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID, rbac.RoleOrgAdmin(adminUser.OrganizationID)) | ||
orgAdminUser, err := orgAdminClient.User(ctx, codersdk.Me) | ||
require.NoError(t, err) | ||
|
||
// With admin, member, and org admin | ||
const ( | ||
readAllUsers = "read-all-users" | ||
readOrgWorkspaces = "read-org-workspaces" | ||
readMyself = "read-myself" | ||
readOwnWorkspaces = "read-own-workspaces" | ||
) | ||
params := map[string]codersdk.AuthorizationCheck{ | ||
readAllUsers: { | ||
Object: codersdk.AuthorizationObject{ | ||
ResourceType: "users", | ||
}, | ||
Action: "read", | ||
}, | ||
readMyself: { | ||
Object: codersdk.AuthorizationObject{ | ||
ResourceType: "users", | ||
OwnerID: "me", | ||
}, | ||
Action: "read", | ||
}, | ||
readOwnWorkspaces: { | ||
Object: codersdk.AuthorizationObject{ | ||
ResourceType: "workspaces", | ||
OwnerID: "me", | ||
}, | ||
Action: "read", | ||
}, | ||
readOrgWorkspaces: { | ||
Object: codersdk.AuthorizationObject{ | ||
ResourceType: "workspaces", | ||
OrganizationID: adminUser.OrganizationID.String(), | ||
}, | ||
Action: "read", | ||
}, | ||
} | ||
|
||
testCases := []struct { | ||
Name string | ||
Client *codersdk.Client | ||
UserID uuid.UUID | ||
Check codersdk.AuthorizationResponse | ||
}{ | ||
{ | ||
Name: "Admin", | ||
Client: adminClient, | ||
UserID: adminUser.UserID, | ||
Check: map[string]bool{ | ||
readAllUsers: true, | ||
readMyself: true, | ||
readOwnWorkspaces: true, | ||
readOrgWorkspaces: true, | ||
}, | ||
}, | ||
{ | ||
Name: "OrgAdmin", | ||
Client: orgAdminClient, | ||
UserID: orgAdminUser.ID, | ||
Check: map[string]bool{ | ||
readAllUsers: false, | ||
readMyself: true, | ||
readOwnWorkspaces: true, | ||
readOrgWorkspaces: true, | ||
}, | ||
}, | ||
{ | ||
Name: "Member", | ||
Client: memberClient, | ||
UserID: memberUser.ID, | ||
Check: map[string]bool{ | ||
readAllUsers: false, | ||
readMyself: true, | ||
readOwnWorkspaces: true, | ||
readOrgWorkspaces: false, | ||
}, | ||
}, | ||
} | ||
|
||
for _, c := range testCases { | ||
c := c | ||
|
||
t.Run("CheckAuthorization/"+c.Name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) | ||
t.Cleanup(cancel) | ||
|
||
resp, err := c.Client.CheckAuthorization(ctx, codersdk.AuthorizationRequest{Checks: params}) | ||
require.NoError(t, err, "check perms") | ||
require.Equal(t, c.Check, resp) | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
coderd/database/migrations/000051_comment_on_api_key_secret.down.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- noop, comments don't need to be removed |
2 changes: 2 additions & 0 deletions
2
coderd/database/migrations/000051_comment_on_api_key_secret.up.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
COMMENT ON COLUMN api_keys.hashed_secret | ||
IS 'hashed_secret contains a SHA256 hash of the key secret. This is considered a secret and MUST NOT be returned from the API as it is used for API key encryption in app proxying code.'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.