-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[server] Restrict snapshot access based on repository access #8306
Conversation
Codecov Report
@@ Coverage Diff @@
## main #8306 +/- ##
=========================================
+ Coverage 8.42% 11.17% +2.75%
=========================================
Files 33 18 -15
Lines 2339 993 -1346
=========================================
- Hits 197 111 -86
+ Misses 2137 880 -1257
+ Partials 5 2 -3
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
LGTM codewise, haven't tested |
Many thanks! Holding because I'd like to see if I can detect the missing integration, and at least show a "Connect" button on the error screen in that case. /hold |
@jankeromnes I think the error screen needs a little love (per issue) Showing the provider 403 error string is ok'ish, but because of the change relative to existing snapshot behavior, we also need to show a message like:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM as well
I like the WorkspaceLogAccessGuard → RepositoryResourceGuard refactoring 👍
1ec4d35
to
0e09d0a
Compare
Okay, checking for a connected provider, and throwing a proper However, after authorizing, starting my own snapshot for a public repo fails 🙄 I'm not sure whether that's a bug in my changes, or a bug somewhere else in Gitpod / core-dev. Checking the logs, I see a few worrying messages: {
"message": "unable to parse URL from normalized contextURL: 'snapshot/bb410d69-12cf-45f2-be53-ee7c030cf335'",
"error": `TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (node:internal/errors:371:5)
at onParseError (node:internal/url:552:9)
at new URL (node:internal/url:628:5)
at Object.getNormalizedURL (/app/node_modules/@gitpod/gitpod-protocol/lib/context-url.js:38:20)
at RepositoryResourceGuard.<anonymous> (/app/node_modules/@gitpod/server/dist/src/auth/resource-access.js:379:61)
at Generator.next (<anonymous>)
at /app/node_modules/@gitpod/server/dist/src/auth/resource-access.js:13:71
at new Promise (<anonymous>)
at __awaiter (/app/node_modules/@gitpod/server/dist/src/auth/resource-access.js:9:12)
at RepositoryResourceGuard.canAccess (/app/node_modules/@gitpod/server/dist/src/auth/resource-access.js:369:16)
at /app/node_modules/@gitpod/server/dist/src/auth/resource-access.js:48:64
at Array.map (<anonymous>)
at CompositeResourceAccessGuard.<anonymous> (/app/node_modules/@gitpod/server/dist/src/auth/resource-access.js:48:53)
at Generator.next (<anonymous>)
at /app/node_modules/@gitpod/server/dist/src/auth/resource-access.js:13:71
at new Promise (<anonymous>)`
}
{
"message": "Request createWorkspace unsuccessful: 460/\"unable to parse ContextURL: undefined\"",
"payload": {
"method": "createWorkspace",
"args": [
{
"contextUrl": "snapshot/f012085f-5c9e-4f1b-8d44-c6cac2d5fa17",
"mode": "select-if-running",
"forceDefaultConfig": false
}, { "_isCancelled":false }
]
}
} and: {
"message": "cannot watch imagebuild logs for workspaceId",
"error": `Error: upstream ended with status code: 2
at /app/node_modules/@gitpod/server/dist/src/workspace/headless-log-service.js:135:37
at /app/node_modules/@gitpod/supervisor-api-grpcweb/lib/status_pb_service.js:259:9
at Array.forEach (<anonymous>)
at onEnd (/app/node_modules/@gitpod/supervisor-api-grpcweb/lib/status_pb_service.js:258:21)
at /app/node_modules/@improbable-eng/grpc-web/dist/grpc-web-client.js:1:11490
at Array.forEach (<anonymous>)
at e.rawOnError (/app/node_modules/@improbable-eng/grpc-web/dist/grpc-web-client.js:1:11452)
at e.onTransportEnd (/app/node_modules/@improbable-eng/grpc-web/dist/grpc-web-client.js:1:10318)
at WebSocket.ws.onclose (/app/node_modules/@gitpod/server/dist/src/util/grpc-web-ws-transport.js:86:25)
at WebSocket.onClose (/app/node_modules/ws/lib/event-target.js:136:16)
at WebSocket.emit (node:events:390:28)
at WebSocket.emit (node:domain:475:12)
at WebSocket.emitClose (/app/node_modules/ws/lib/websocket.js:236:12)
at Object.onceWrapper (node:events:509:28)
at ClientRequest.emit (node:events:390:28)
at ClientRequest.emit (node:domain:475:12)`
}
{
"message": "Request watchWorkspaceImageBuildLogs unsuccessful: 640/\"cannot watch imagebuild logs for workspaceId\"",
"payload": {
"method": "watchWorkspaceImageBuildLogs",
"args": [ "bronze-goat-sbkglq6tewo", {"_isCancelled":false} ]
}
} Questions:
|
Left to do:
|
580c136
to
0f83683
Compare
Hmm, I've added some debug logs, but could not reproduce the errors above. I guess this works as expected now. ✅ I've also added a more specific error message when you don't have repo access: Integration connected, repo access Opening the snapshot works ✅ Integration connected, no repo access Integration not connected (can't verify access) I feel like we could still make these error pages look nicer somehow, but this could be a follow-up issue. 💭 Ready for final approval. 🚢 |
2cf8ab5
to
a989331
Compare
components/server/src/bitbucket-server/bitbucket-server-repository-provider.ts
Outdated
Show resolved
Hide resolved
@@ -14,4 +14,5 @@ export interface RepositoryProvider { | |||
getBranches(user: User, owner: string, repo: string): Promise<Branch[]>; | |||
getCommitInfo(user: User, owner: string, repo: string, ref: string): Promise<CommitInfo | undefined>; | |||
getUserRepos(user: User): Promise<string[]>; | |||
hasReadAccess(user: User, owner: string, repo: string): Promise<boolean>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
Also refactor: - Simplify GuardedSnapshot.workspace - WorkspaceLogAccessGuard → RepositoryResourceGuard - RepositoryService.canAccessHeadlessLogs → RepositoryProvider.hasReadAccess
a989331
to
42f1a54
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This looks good now @jankeromnes - thanks for improving the error message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merci bien
Many thanks for the reviews! 🙏 Releasing the hold-down clamps, go for launch 🚀 /unhold |
Description
Restrict snapshot access based on repository access.
Also refactors:
GuardedSnapshot.workspace
(simplified)WorkspaceLogAccessGuard
→RepositoryResourceGuard
RepositoryService.canAccessHeadlessLogs
→RepositoryProvider.hasReadAccess
Related Issue(s)
Fixes #8257
How to test
Also:
Release Notes
Documentation