[DT-507] fix(security): require Keycloak login on all APIs and harden the backend - #47
Open
devajipatil wants to merge 32 commits into
Open
[DT-507] fix(security): require Keycloak login on all APIs and harden the backend#47devajipatil wants to merge 32 commits into
devajipatil wants to merge 32 commits into
Conversation
…ement-console into feature/keycloak-bpn
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ement-console into feature/keycloak-bpn
…ement-console into feature/keycloak-bpn
…36/edc-management-console into feature/backend-rollout-strategy
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Require login on all APIs, and general security hardening
Why this change was needed
The backend has APIs to deploy and delete EDC connectors, DTRs and submodel
servers. These APIs were supposed to be protected by an API key.
They were not protected at all.
The code looked for the setting
authorizationat the top of the configfile, but in the config file that setting lives one level down, inside
appConfig. Because the code looked in the wrong place, it found nothing,assumed "protection is switched off", and let every request through.
In practice: anyone who could reach the backend URL could list every
company's deployments, deploy new ones, and delete existing ones, without
logging in and without any password or key.
Separately, a few other things were unsafe:
problem and carried on instead of refusing the request.
KEYCLOAK_VERIFY_SIGNATURE=false) that turned offtoken checking completely.
traffic could be intercepted.
(for example
my-edc-password), and the component name is shown in theUI. So the password was guessable by anyone looking at the dashboard.
the database credentials it carried.
stayed after logout and could be stolen by any script on the page.
What changed
Login is now required. All 11 API routes require a valid Keycloak token.
The backend checks the signature against Keycloak's public keys, checks the
token came from the right Keycloak realm, checks it has not expired, and
checks it was issued for this application. If any check fails, the request
gets 401 Unauthorized.
The API-key path was deleted. It never actually protected anything, so
removing it is safe and means one less thing to maintain.
Both ways of skipping the checks were removed. There is no longer any
code path that reads a token without verifying it.
HTTPS certificates are now verified on all outbound calls (6 places).
Database passwords are now generated by the backend — 24 random
characters. Components that already exist keep their current password, so
upgrading a running component cannot break its database.
Leaks closed. Deployment logs now record only the component type and
name. The token is no longer stored in localStorage (and any old copy is
deleted when the page loads). The frontend no longer invents a password
value to keep in memory.
Safer defaults. CORS only allows the console's own address instead of
allowing everything.
/docs,/redocand/openapi.jsonare no longerpublic. The frontend now sends standard security headers (HSTS,
X-Frame-Options, nosniff, Referrer-Policy).
Files changed (12 files, +105 / -155)
backend/auth/keycloak_config.pybackend/init.pybackend/managers/edcManager.pybackend/service/edcService.pybackend/config/configuration.ymlbackend/tests/test_identity.pyfrontend/.nginx/nginx.conffrontend/src/api/client.ts,main.tsxfrontend/src/AppNew.tsx,ComponentWizard.tsx,utils/deployment.tsBefore you deploy — one required step
Add
EMC_ALLOWED_ORIGINStobackend.envin each chart values file, set tothe address of the console frontend (not the backend):
No trailing slash. If it is missing, the backend logs an error at startup
and the dashboard will load but show no data. If it is set to the wrong
address there is no error in the backend log — the browser just blocks the
response — so please test in dev first.
What will break
token now gets 401. It needs a token.
VITE_DISABLE_AUTH=truewill get 401. Wedeliberately did not add a "skip auth" switch to the backend, because that
is exactly the hole this PR closes.
certificates will now fail instead of silently passing. This may reveal
existing certificate problems in dev.
Still to do (not in this PR)
Any logged-in user can still see and delete every company's
deployments. Login is now required, but there is no per-company
separation and no read-only role. This is the biggest remaining gap and
should be the next ticket.
emc-api-key,appConfig.authorizationandVITE_API_KEYare nowunused and can be deleted from the chart values.