Skip to content

Commit

Permalink
fix distribution api calls (routing in express was wrong), enforce _ …
Browse files Browse the repository at this point in the history
…after the tenant name in resource names
  • Loading branch information
s4ke committed Oct 16, 2024
1 parent bcc72c6 commit f7d9816
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
registry_auth_overrides.json

# Logs
logs
*.log
Expand Down
13 changes: 2 additions & 11 deletions swarmgate/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,10 @@ function getAuthForDockerImage(image: string): {
registry: string
} {
let registry = getRegistryFromDockerImage(image);
console.log(`detected registry: ${registry} for image ${image}`);
if (!registry) {
registry = 'docker.io';
}
const auth = getAuthForRegistry(registry);
console.log(`auth for registry ${registry}: ${JSON.stringify({
anonymous: auth?.anonymous,
username: auth?.username,
email: auth?.email,
password: "***",
serveraddress: auth?.serveraddress
})}`);
return {
auth: auth,
registry: registry
Expand All @@ -88,10 +80,9 @@ function getAuthForDockerImage(image: string): {

export function setupRoutes(tenantLabelValue: string) {
const router = express.Router();
const namePrefix = process.env.NAME_PREFIX || tenantLabelValue;

function isResourceNameAllowed(name: string): boolean {
if (name.startsWith(namePrefix)) {
if (name.startsWith(tenantLabelValue + '_')) {
return true;
}
return false;
Expand Down Expand Up @@ -224,7 +215,7 @@ export function setupRoutes(tenantLabelValue: string) {
router.get('/:version?/info', proxyRequestToDockerWithStrippedAuthInfo);

// make image resolution work
router.get('/:version?/distribution/:name/json', async (req: express.Request, res: express.Response) => {
router.get('/:version?/distribution/:name(*)/json', async (req: express.Request, res: express.Response) => {
console.log("distribution json for image", req.params.name);

stripAuthInfo(req);
Expand Down

0 comments on commit f7d9816

Please sign in to comment.