Skip to content

Commit f46c6e6

Browse files
committed
anonymous localstack
1 parent 9df6140 commit f46c6e6

5 files changed

Lines changed: 50 additions & 10 deletions

File tree

.openapis

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
# This file is *safe* to add to source control and will increase the speed of builds
77
---
88
- serviceName: auth-sls-rest-api
9-
version: 1.0.1-5
9+
version: 1.0.1-6
1010

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@types/dotenv": "^8.2.0",
2727
"@types/express": "^4.17.11",
2828
"@types/node": "14",
29+
"@types/seedrandom": "^3.0.2",
2930
"@typescript-eslint/eslint-plugin": "^4.29.3",
3031
"@typescript-eslint/parser": "^4.29.3",
3132
"cross-env": "^7.0.3",
@@ -58,7 +59,8 @@
5859
"joi": "^17.4.0",
5960
"joi-to-typescript": "^1.12.0",
6061
"moment": "^2.29.1",
62+
"seedrandom": "^3.0.5",
6163
"tsoa": "^3.8.0",
6264
"ulid": "^2.3.0"
6365
}
64-
}
66+
}

src/services/GithubService.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { TerraformError } from '../interfaces/errors';
44
import { Identity } from '../models/interfaces';
55
import crypto from 'crypto';
66
import { IdentityModel } from '../models/IdentityModel';
7+
import seedrandom from 'seedrandom';
78

89
export type IdentityWithToken = Identity & {
910
token: string;
@@ -44,6 +45,12 @@ export class GithubService {
4445
const decoded = Buffer.from(token, 'base64').toString('utf8');
4546

4647
const [username, password] = decoded.split(':');
48+
49+
// Unauthenticated state storage for localstack
50+
if (username === 'localstack' && password === 'localstack') {
51+
return this.inferLocalstackIdentity();
52+
}
53+
4754
let owner: string | undefined;
4855
let repo: string | undefined;
4956
let workspace: string | undefined;
@@ -205,4 +212,33 @@ export class GithubService {
205212
`Unable to determine owner and/or repository from token privileges. Ensure \`username\` is in the format of \`{owner}/{repository}\`, and the provided \`password\` (a GitHub token) has access to that repository.`,
206213
);
207214
};
215+
216+
// TODO: support 'who' from State Lock Request
217+
private inferLocalstackIdentity = (who = 'unknown@unknown'): IdentityWithToken => {
218+
const tokenSha = crypto.createHash('sha256').update(who).digest().toString('base64');
219+
220+
const [username, host] = who.split('@');
221+
if (!username || !host) {
222+
throw new Error(`Invalid format for \`Who\` on state lock request`);
223+
}
224+
225+
// Set IDs as negative so they're clearly out of valid range
226+
const ownerId = seedrandom(host).int32() * -1;
227+
const repoId = seedrandom(username).int32() * -1;
228+
229+
return {
230+
pk: IdentityModel.prefix('pk', tokenSha),
231+
sk: IdentityModel.prefix('sk'),
232+
owner: host,
233+
ownerId,
234+
repo: username,
235+
repoId,
236+
token: who,
237+
tokenSha: tokenSha,
238+
workspace: 'default',
239+
meta: {
240+
name: 'localstack',
241+
},
242+
};
243+
};
208244
}

src/services/StateService.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ export class StateService {
8383
};
8484

8585
public getState = async (identity: IdentityWithToken): Promise<any> => {
86-
console.log(`!!! pk search`, StateModel.prefix('pk', identity.ownerId));
87-
console.log(
88-
`!!! sk search`,
89-
StateModel.prefix('sk', `${identity.repoId}_${identity.workspace}`),
90-
);
91-
9286
const state = await this.stateModel.model.get(
9387
StateModel.prefix('pk', identity.ownerId),
9488
StateModel.prefix('sk', `${identity.repoId}_${identity.workspace}`),
@@ -111,8 +105,6 @@ export class StateService {
111105
const s3 = await S3();
112106
const download = await s3.getObject({ Bucket: s3Meta.bucket, Key: s3Meta.key }).promise();
113107

114-
console.log(`!!! download`, download);
115-
116108
const { Body } = download;
117109

118110
if (!Body) {

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,6 +2382,11 @@
23822382
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.1.tgz#d8f1c0d0dc23afad6dc16a9e993a0865774b4065"
23832383
integrity sha512-xoDlM2S4ortawSWORYqsdU+2rxdh4LRW9ytc3zmT37RIKQh6IHyKwwtKhKis9ah8ol07DCkZxPt8BBvPjC6v4g==
23842384

2385+
"@types/seedrandom@^3.0.2":
2386+
version "3.0.2"
2387+
resolved "https://registry.yarnpkg.com/@types/seedrandom/-/seedrandom-3.0.2.tgz#7f30db28221067a90b02e73ffd46b6685b18df1a"
2388+
integrity sha512-YPLqEOo0/X8JU3rdiq+RgUKtQhQtrppE766y7vMTu8dGML7TVtZNiiiaC/hhU9Zqw9UYopXxhuWWENclMVBwKQ==
2389+
23852390
"@types/serve-static@*":
23862391
version "1.13.10"
23872392
resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.13.10.tgz#f5e0ce8797d2d7cc5ebeda48a52c96c4fa47a8d9"
@@ -10634,6 +10639,11 @@ schema-utils@^3.0.0:
1063410639
ajv "^6.12.5"
1063510640
ajv-keywords "^3.5.2"
1063610641

10642+
seedrandom@^3.0.5:
10643+
version "3.0.5"
10644+
resolved "https://registry.yarnpkg.com/seedrandom/-/seedrandom-3.0.5.tgz#54edc85c95222525b0c7a6f6b3543d8e0b3aa0a7"
10645+
integrity sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==
10646+
1063710647
seek-bzip@^1.0.5:
1063810648
version "1.0.6"
1063910649
resolved "https://registry.yarnpkg.com/seek-bzip/-/seek-bzip-1.0.6.tgz#35c4171f55a680916b52a07859ecf3b5857f21c4"

0 commit comments

Comments
 (0)