-
-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #766 from schummar/feature/buildkit-support
POC: BuildKit support
- Loading branch information
Showing
7 changed files
with
419 additions
and
124 deletions.
There are no files selected for viewing
This file contains 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 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,54 @@ | ||
syntax = "proto3"; | ||
|
||
package moby.filesync.v1; | ||
|
||
option go_package = "auth"; | ||
|
||
service Auth{ | ||
rpc Credentials(CredentialsRequest) returns (CredentialsResponse); | ||
rpc FetchToken(FetchTokenRequest) returns (FetchTokenResponse); | ||
rpc GetTokenAuthority(GetTokenAuthorityRequest) returns (GetTokenAuthorityResponse); | ||
rpc VerifyTokenAuthority(VerifyTokenAuthorityRequest) returns (VerifyTokenAuthorityResponse); | ||
} | ||
|
||
message CredentialsRequest { | ||
string Host = 1; | ||
} | ||
|
||
message CredentialsResponse { | ||
string Username = 1; | ||
string Secret = 2; | ||
} | ||
|
||
message FetchTokenRequest { | ||
string ClientID = 1; | ||
string Host = 2; | ||
string Realm = 3; | ||
string Service = 4; | ||
repeated string Scopes = 5; | ||
} | ||
|
||
message FetchTokenResponse { | ||
string Token = 1; | ||
int64 ExpiresIn = 2; // seconds | ||
int64 IssuedAt = 3; // timestamp | ||
} | ||
|
||
message GetTokenAuthorityRequest { | ||
string Host = 1; | ||
bytes Salt = 2; | ||
} | ||
|
||
message GetTokenAuthorityResponse { | ||
bytes PublicKey = 1; | ||
} | ||
|
||
message VerifyTokenAuthorityRequest { | ||
string Host = 1; | ||
bytes Payload = 2; | ||
bytes Salt = 3; | ||
} | ||
|
||
message VerifyTokenAuthorityResponse { | ||
bytes Signed = 1; | ||
} |
This file contains 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,63 @@ | ||
var grpc = require("@grpc/grpc-js"), | ||
protoLoader = require("@grpc/proto-loader"), | ||
path = require("path"), | ||
uuid = require("uuid").v4; | ||
|
||
function withSession(docker, auth, handler) { | ||
const sessionId = uuid(); | ||
|
||
const opts = { | ||
method: "POST", | ||
path: "/session", | ||
hijack: true, | ||
headers: { | ||
Upgrade: "h2c", | ||
"X-Docker-Expose-Session-Uuid": sessionId, | ||
"X-Docker-Expose-Session-Name": "testcontainers", | ||
}, | ||
statusCodes: { | ||
200: true, | ||
500: "server error", | ||
}, | ||
}; | ||
|
||
docker.modem.dial(opts, function (err, socket) { | ||
if (err) { | ||
return handler(err, null, () => undefined); | ||
} | ||
|
||
const server = new grpc.Server(); | ||
const creds = grpc.ServerCredentials.createInsecure(); | ||
const injector = server.createConnectionInjector(creds); | ||
injector.injectConnection(socket); | ||
|
||
const pkg = protoLoader.loadSync( | ||
path.resolve(__dirname, "proto", "auth.proto") | ||
); | ||
const service = grpc.loadPackageDefinition(pkg); | ||
|
||
server.addService(service.moby.filesync.v1.Auth.service, { | ||
Credentials({ request }, callback) { | ||
// We probably want to have the possibility to pass credentials per | ||
// hots. The correct one could be returned based on `request.Host` | ||
if (auth) { | ||
callback(null, { | ||
Username: auth.username, | ||
Secret: auth.password, | ||
}); | ||
} else { | ||
callback(null, {}); | ||
} | ||
}, | ||
}); | ||
|
||
function done() { | ||
server.forceShutdown(); | ||
socket.end(); | ||
} | ||
|
||
handler(null, sessionId, done); | ||
}); | ||
} | ||
|
||
module.exports = withSession; |
Oops, something went wrong.