10abd36340
Authentication previously implied full authorization: any valid token could manage every host, DNS provider, domain, and user. This adds SSO login and a per-domain rights model. OIDC login (authorization_code + PKCE): - conf.oidc + conf.auth blocks; clientSecret in (gitignored) secrets.js. - utils/oidc.js (state/PKCE, code exchange, userinfo) using global fetch. - models/oidc_state.js: short-lived state store, auto-expiring via model-redis 1.5 per-key TTL. - routes/auth.js: GET /auth/oidc/start + /auth/oidc/callback; JIT-provisions a local user, mints an AuthToken carrying the SSO groups, hands the token to the browser via a URL fragment. "Log in with SSO" button on the login page. Authorization (groups + app overrides, per-domain, with ownership): - models/grant.js + utils/roles.js (pure, unit-tested): effective rights from conf.auth (admin users/groups, group->role map), Grant records (user|group -> global|domain -> viewer|manager|admin), and ownership (created_by). Roles rank admin > manager(owner) > viewer. - AuthToken stores session groups; middleware/auth.js exposes req.groups. - middleware/authz.js: requireAdmin, requireDomainRole(minRole, resolveDomain), filterViewable. Applied across routes: host mutations need manager on the host's domain; reads are filtered to visible domains; DNS providers, user management, and grant management are global-admin-only; certs need viewer. - routes/grant.js: admin CRUD for grants. Anti-lockout via conf.auth.adminUsers plus migrations/grant_bootstrap.js. Frontend: /me returns effective rights; nav gates Users/Grants to admins; grants management page; OIDC token-fragment handling in app-base.js. Tests: utils/roles and utils/oidc unit-tested (no redis); wired into the test scripts. Full suite 89 pass. Also verified end-to-end against redis (grant resolution, middleware allow/deny/403, list filtering) and the OIDC pure flow. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
96 lines
3.0 KiB
Plaintext
Executable File
96 lines
3.0 KiB
Plaintext
Executable File
<%- include('top') %>
|
|
<script type="text/javascript">
|
|
|
|
// If we arrived from the OIDC callback with a token in the URL fragment,
|
|
// store it and forward on before doing anything else.
|
|
if(!app.auth.consumeTokenFragment()){
|
|
app.auth.isLoggedIn(function(error, isLoggedIn){
|
|
if(isLoggedIn){
|
|
app.auth.logInRedirect();
|
|
}else{
|
|
// Reveal the login card once we know the user is not logged in.
|
|
document.getElementById('login-card-row').style.display = '';
|
|
}
|
|
})
|
|
}
|
|
|
|
</script>
|
|
|
|
<div id="login-card-row" class="row" style="display: none;">
|
|
<div class="col-md-4">
|
|
<div class="shadow-lg card">
|
|
|
|
<div class="card-header text-center">
|
|
<span class="card-icon float-start">
|
|
<i class="fa-solid fa-lock"></i>
|
|
</span>
|
|
<span class="card-title">
|
|
User Login
|
|
</span>
|
|
<span class="float-end">
|
|
<i class="fa-solid fa-circle-minus"></i>
|
|
</span>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="card-header shadow actionMessage" style="display:none"></div>
|
|
<div class="card-body">
|
|
<form action="auth/login" onsubmit="formAJAX(this)" evalAJAX="
|
|
app.auth.setToken(data.token);
|
|
app.auth.logInRedirect();
|
|
">
|
|
<input type="hidden" name="redirect" value="<%= redirect %>">
|
|
|
|
<div class="mb-3">
|
|
<label></label>
|
|
<div class="input-group">
|
|
<span class="input-group-text" id="addon-wrapping"><i class="fa-solid fa-user-tie"></i></span>
|
|
<input type="text" name="username" class="form-control" placeholder="jsmith" aria-label="Username" aria-describedby="addon-wrapping">
|
|
</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<div class="input-group">
|
|
<span class="input-group-text" id="addon-wrapping"><i class="fa-solid fa-key"></i></span>
|
|
<input type="password" name="password" class="form-control" placeholder="huunteR!23" aria-label="Username" aria-describedby="addon-wrapping">
|
|
</div>
|
|
</div>
|
|
|
|
<!-- <div class="group">
|
|
<label class="control-label">User name</label>
|
|
<div class="input-group mb-3 shadow">
|
|
<div class="input-group-prepend">
|
|
<span class="input-group-text" ><i class="fa-solid fa-user-tie"></i></span>
|
|
</div>
|
|
<input type="text" name="username" class="input-control" placeholder="jsmith" />
|
|
</div>
|
|
</div>
|
|
|
|
<div class="group">
|
|
<label class="control-label">Password</label>
|
|
<div class="input-group mb-3 shadow">
|
|
<div class="input-group-prepend">
|
|
<span class="input-group-text" ><i class="fa-solid fa-key"></i></span>
|
|
</div>
|
|
<input type="password" name="password" class="input-control" placeholder="hunter123!"/>
|
|
</div>
|
|
</div> -->
|
|
<hr />
|
|
<button type="submit" class="btn btn-outline-dark"><i class="fa-solid fa-right-to-bracket"></i> Log in</button>
|
|
</form>
|
|
|
|
<hr />
|
|
<div class="d-grid">
|
|
<a href="/api/auth/oidc/start" class="btn btn-outline-primary">
|
|
<i class="fa-solid fa-id-badge"></i> Log in with SSO
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<%- include('bottom') %>
|