ci: create CI user directly in DB (bypasses bootstrap 409)
Some checks failed
Some checks failed
The auth/bootstrap endpoint fails with 409 because mcpd's startup creates a system user (system@mcpctl.local), making the "no users exist" check fail. Instead, create the CI user, session token, and RBAC definition directly in postgres via Prisma. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -142,24 +142,46 @@ jobs:
|
|||||||
echo "::error::mcpd failed to start within 30s"
|
echo "::error::mcpd failed to start within 30s"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
- name: Bootstrap auth and write credentials
|
- name: Create CI user and session
|
||||||
run: |
|
run: |
|
||||||
RESULT=$(curl -s -w "\nHTTP_STATUS:%{http_code}" -X POST http://localhost:3100/api/v1/auth/bootstrap \
|
node -e "
|
||||||
-H 'Content-Type: application/json' \
|
const { PrismaClient } = require('@prisma/client');
|
||||||
-d '{"email":"ci@test.local","password":"ci-smoke-test"}')
|
const crypto = require('crypto');
|
||||||
HTTP_CODE=$(echo "$RESULT" | tail -1 | sed 's/HTTP_STATUS://')
|
const bcrypt = require('bcrypt');
|
||||||
BODY=$(echo "$RESULT" | sed '$d')
|
(async () => {
|
||||||
echo "Bootstrap response (HTTP $HTTP_CODE): $BODY"
|
const prisma = new PrismaClient();
|
||||||
if [ "$HTTP_CODE" -ge 400 ]; then
|
const hash = await bcrypt.hash('ci-smoke-test', 10);
|
||||||
echo "::error::Bootstrap failed with HTTP $HTTP_CODE"
|
const user = await prisma.user.upsert({
|
||||||
exit 1
|
where: { email: 'ci@test.local' },
|
||||||
fi
|
create: { email: 'ci@test.local', name: 'CI', passwordHash: hash, role: 'USER' },
|
||||||
mkdir -p ~/.mcpctl
|
update: { passwordHash: hash },
|
||||||
echo "$BODY" | node -e "
|
});
|
||||||
const res = JSON.parse(require('fs').readFileSync('/dev/stdin','utf-8'));
|
const token = crypto.randomBytes(32).toString('hex');
|
||||||
const creds = {token: res.token, mcpdUrl: 'http://localhost:3100', user: 'ci@test.local'};
|
await prisma.session.create({
|
||||||
require('fs').writeFileSync(require('os').homedir()+'/.mcpctl/credentials', JSON.stringify(creds));
|
data: { token, userId: user.id, expiresAt: new Date(Date.now() + 86400000) },
|
||||||
console.log('Credentials written');
|
});
|
||||||
|
// Grant full RBAC permissions
|
||||||
|
await prisma.rbacDefinition.create({
|
||||||
|
data: {
|
||||||
|
name: 'ci-admin',
|
||||||
|
subjects: [{ kind: 'User', name: 'ci@test.local' }],
|
||||||
|
roleBindings: [
|
||||||
|
{ role: 'edit', resource: '*' },
|
||||||
|
{ role: 'run', resource: '*' },
|
||||||
|
{ role: 'run', action: 'logs' },
|
||||||
|
{ role: 'run', action: 'backup' },
|
||||||
|
{ role: 'run', action: 'restore' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const os = require('os'), fs = require('fs'), path = require('path');
|
||||||
|
const dir = path.join(os.homedir(), '.mcpctl');
|
||||||
|
fs.mkdirSync(dir, { recursive: true });
|
||||||
|
fs.writeFileSync(path.join(dir, 'credentials'),
|
||||||
|
JSON.stringify({ token, mcpdUrl: 'http://localhost:3100', user: 'ci@test.local' }));
|
||||||
|
console.log('CI user + session + RBAC created, credentials written');
|
||||||
|
await prisma.\$disconnect();
|
||||||
|
})();
|
||||||
"
|
"
|
||||||
|
|
||||||
- name: Create mcpctl CLI wrapper
|
- name: Create mcpctl CLI wrapper
|
||||||
|
|||||||
Reference in New Issue
Block a user