Skip to main content

Security

Roles​

The doc service authorizes against semantic roles, which requires jeap.security.oauth2.resourceserver.system-name to be set on the instance:

RoleGrants
<system-name>_%<system>_@uploads_#writeUploading documentation for the system named in the tenant part
<system-name>_%<site>_@site-uploads_#writeUploading the tree of the static site named in the tenant part
<system-name>_@docs_#readA name kept free by convention; nothing in the service checks it
<system-name>_@sites_#adminAsking for a documentation site to be published, and removing a part the site no longer has
<system-name>_@sites_#readReading what the documentation generator has been doing
<system-name>_@governance-notifications_#writeCalling the governance webhook - see below

A site is nobody's system​

The two sites roles carry no tenant part, and that is the point. The upload role is granted per system so that a pipeline can only change its own system's documentation - while a build regenerates a whole part of it, with the documentation of every system on it. Granting it through a system's tenant would hand each pipeline a lever over everybody else's documentation, so administering a site is its own resource, granted to whoever operates the instance rather than to the pipelines that fill it.

Reading is a separate operation from administering: #read answers what the generator has been doing and #admin sets it off, and neither implies the other.

The governance webhook​

governance-notifications carries no tenant either: the call reports that a scoring run of the whole Governance Service completed, which is not any one system's or site's. It is granted to the Governance Service's own client, not to a build pipeline - see the API and Importing the Governance Service.

A system may only change its own documentation​

The system a documentation set belongs to is a parameter of the upload, and the write role carries the system it is granted for in its tenant part, so the service authorizes every upload against exactly that system. The role names the resource uploads because the upload is the API resource a pipeline acts on. The same role is what a pipeline reads the state of its own uploads with (GET /api/uploads/docs/{uploadId}), and it covers every kind of upload the family will hold.

A pipeline holding <system-name>_%orders_@uploads_#write can upload documentation for the system orders and receives 403 for every other system. Granting the role without a tenant part makes it a wildcard over all systems, which is what an administrative client would hold.

Removing documentation takes the same role, granted for the same system: DELETE /api/docs/custom/sets and /api/docs/custom/subjects are a system changing its own documentation, which is what the write role says. A resource of their own would have to be rolled out to every pipeline before either could be used, and would say nothing the tenant part does not already say.

Or the sites administrator, on both of them. The write role is the right rule while there is a pipeline holding it, and there is not always: a repository gets archived, a component gets renamed, a team is disbanded, and the set stays current with nobody able to remove it. Removing documentation is not a step towards reading anything else, so accepting <system-name>_@sites_#admin there grants no access it did not already imply.

And DELETE /api/docs/custom/systems is the administrator's alone. It removes everything documented for a system - its own documentation and that of every component and library under it, which several teams may own - so it is not something one system's pipeline may do.

A static site is uploaded for the site​

A static site's tree belongs to the site, not to a system, so it is uploaded with a role of its own: <system-name>_%<site>_@site-uploads_#write, with the site in the tenant part. A holder may upload to that site and to no other, and receives 403 for a static site it is not granted. The resource differs from uploads on purpose: a site's id is never read as a system's name in the tenant part, and a system's upload role never reaches a static site. Granted without a tenant part, the role covers every static site - for the operator of the instance rather than for a pipeline.

The same role reads the state of such an upload (?site=<id>), checks a tree before it is uploaded (type=site-docs&site=<id> on the validation endpoint) and removes the tree again (DELETE /api/docs/custom/sites?site=<id>, which an administrator of the sites may call as well).

Authentication​

The REST API is an OAuth2 resource server: clients authenticate with a bearer token, in the SYS context for a build pipeline.

The documentation itself is open​

The generated documentation is served to anyone who can reach the service, with no token and no role. That is a decision rather than an omission: architecture documentation everyone in the organisation should be able to read is of no use behind a bearer token a browser does not have, and the alternative - a login flow with a session - is not something this service does. What is protected is changing the documentation, which is what the roles above are for.

What the pages read in the browser is open too, and read-only. It is below /ui-api - a root of its own beside /api, with a security filter chain of its own that answers GET and HEAD without a token and refuses every other method. /api/** stays "a bearer token, always", without an exception carved into it. Nothing below /ui-api answers what the open sites would not show: the live status of a site (see below) and the governance excerpt of a system, which repeats what the governance site publishes. See The REST API.

The actuator keeps its own chain from the jEAP monitoring starter, and /actuator/prometheus stays behind Basic auth - its password has to be set per instance, see Observability.

The site generator gets no credentials​

The documentation site is generated by a child process of the service, and that process is started with an environment built from nothing rather than inherited: the service's own environment holds the database and object storage credentials, and a documentation build has no business seeing them. It also gets a hard timeout and a memory cap, and the site template it runs is installed over the generated content rather than beside it, so nothing that was generated can become part of the program that runs.

What the documentation says about the service​

The About This Documentation page and about-this-documentation.json beside it are part of the published site, and the site's live status - which the service answers at /ui-api/sites/{site}/live-status - is read by that page, so all three are readable by anyone who can reach the service. The live status is deliberately not below /api: it carries the statements the page cannot keep true on its own, and a bearer token in front of a table on a public page would be a token no browser has. What all three may carry is decided in one place - DocumentationProvenance - and not by whoever writes a page:

PublishedNot published
The site and environment ids and labels, the templates, the retentionThe instance that ran a build
The schedules and their next occurrenceThe object prefix a site is published under, and the bucket
How many systems, components and messages a model contributedAny database name, host or credential
When a model was imported, when the repository was last read, and whether the import is behindThe URL of the architecture repository
What a run produced and cost: pages, bytes, durationWhy an import or a build failed

The last row is the one to keep in mind when adding a field. A failure reason is built from what an upstream answered: it quotes hosts, paths and occasionally an error body. That an import failed is publishable; why it failed is not - that stays in the log of the instance and in the API behind a token. DocumentationFacts says so in its javadoc, and its test asserts it over the whole rendering rather than field by field, so a field added later is caught by the test rather than by whoever reads the published page.

Content Security Policy​

The documentation the service will serve is self-contained, so it is served with a restrictive Content Security Policy that allows no external content at all:

default-src 'none'; script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline';
img-src 'self' data:; font-src 'self'; connect-src 'self'; worker-src 'self' blob:; frame-src 'self';
frame-ancestors 'none'; base-uri 'none'; form-action 'none'

Three of those source expressions are there for what the site serves, and all of them are same-origin:

script-src 'unsafe-inline'The generator puts a small inline script into every page that applies the colour mode before the page is painted. Without it every page flashes and the theme toggle is dead
script-src 'wasm-unsafe-eval', worker-src blob:The diagram plugin compiles its rendering engine in the reader's browser. Diagrams are source in the page, not images, so nothing is fetched from a diagram server
frame-src 'self'A page frames uploaded HTML, which is served from this origin. frame-ancestors stays 'none': the site frames, it is not framed

What keeps uploaded content out of a page​

'unsafe-inline' means that any script that ends up inline in a page executes, and pages carry documentation other teams wrote. Two rules keep such a script from getting there in the first place, and they are what the policy rests on:

Raw HTML in a page is escaped, not passed throughplugins/remark-escape-raw-html in the site template turns every raw HTML node into text before Docusaurus renders it, so an uploaded <script> is shown rather than run. It applies to every page of the site, generated or uploaded - the generator writes no raw tags. A fold and a grouped table are directives that the site builds into elements, with no attribute from the page
An uploaded file a browser renders as a document is sandboxedAn SVG carries script and gets this origin when it is opened directly, so SiteHeaders adds sandbox to the policy of such a response. The site's own SVGs are affected too and do not care: they are loaded as images, and an image runs no policy

Replacing 'unsafe-inline' with a hash of the one inline script the generator emits is the stricter way, and it stays open: the hash changes with the theme release and would have to be computed per build. Note that browsers ignore 'unsafe-inline' as soon as a hash or nonce is present, so the two cannot be mixed as a migration step without care.

The policy, and the other security headers, are applied by the jEAP web config starter, which skips the API and the actuator paths.

An uploaded microsite runs with an origin of its own​

Uploaded HTML is served under /microsites/, and every response under that prefix carries a policy that sandboxes it - not only the iframe that frames it, so a file opened directly is as contained as a framed one:

Content-Security-Policy: sandbox allow-scripts allow-popups allow-popups-to-escape-sandbox allow-downloads;
default-src 'self' data: blob:; script-src 'self' 'unsafe-inline' 'unsafe-eval';
style-src 'self' 'unsafe-inline'; connect-src 'self'; frame-ancestors 'self'; base-uri 'self';
form-action 'none'
Access-Control-Allow-Origin: *
Cross-Origin-Resource-Policy: cross-origin
Referrer-Policy: no-referrer
allow-same-origin is never grantedThe microsite is on this service's host. With it, a framed page could remove the iframe's sandbox attribute and reload itself as a same-origin document of the documentation site
Access-Control-Allow-Origin only hereA microsite fetches its own files from an opaque origin, so those are cross-origin requests carrying Origin: null. Nothing else this service answers is one, and a test asserts /api never carries it
What the sandbox protectsThe documentation site's origin, its storage and its cookies, every neighbour application on the host, and the reader's session. A microsite can still do anything a page with no origin can do
What it does not protectThe reader's browser from the microsite's own content: it runs JavaScript, and that is the point - Allure, Javadoc, Swagger UI and Spring REST Docs output all work

The blast radius is the host. A microsite is served from the same host as the documentation, so the sandbox is the whole boundary. It is one header and one attribute, and the test suite asserts both on every response under the prefix - a serving path that forgot them would turn uploaded JavaScript into same-origin JavaScript of the documentation site, and the microsite would still render.

The service also injects one script into every HTML page of a microsite, which gives the sandboxed document an in-memory storage and cookie jar - see The documentation a team writes. It changes nothing about the isolation: the origin stays opaque and nothing is persisted.

What an upload may not do​

Documentation arrives as a ZIP from a build pipeline, and everything below the authorization is about what that archive is allowed to be. The rules are in Upload validation; what matters here is why each of them is a boundary rather than a convenience:

The archive is read to a file before anything is said about itA request body cannot be read twice, and every question about the structure is answered from the entry list - so a set that would not be published is refused before an object exists
Nothing is decompressed while the upload is being decidedWhat is checked is the list of paths and what the archive declares it unpacks to. A refused bundle is refused without an entry ever being unpacked
Three bounds, not oneHow many paths a set may hold, how much it may unpack to, and how large the body may be. An archive that lies about what it unpacks to is stopped again while it is written, by counting the bytes that actually come out
A path has to be publishableRelative, separated by /, free of ., .., a backslash and a control character, and bounded in length. A path that could leave the prefix it is written under never reaches the object storage
An extension denylist for a micrositeA microsite follows no template, so what is refused is what has no business in documentation and every business on a workstation - executables, installers, and the scripts a workstation runs. What contains the rest is the sandbox
One reserved name_jeap-search.tsv is written by the service beside a microsite's files, and a set carrying it is refused. A collision there would let a team's own file and the service's quietly overwrite each other

Malware scanning is not part of this, and is deliberately out of scope: the validation is structural and syntactic. What limits the damage an uploaded file can do is the sandbox it is served in, not an assumption that it is clean.

Reading an uploaded document​

The text inside an uploaded microsite is extracted when the set is uploaded, so that it can be searched - which means this service parses HTML somebody else's build produced, the least trustworthy input it has. Three things bound that:

The parser is in a module of its ownjeap-doc-html, holding one dependency. The domain stays free of infrastructure and nothing else takes the dependency, so the code that touches uploaded HTML is one small, replaceable adapter
It is boundedA fixed number of pages per set and a fixed number of bytes per page. A document larger than that is read down to the cut, and a set with more pages contributes what the cap allows
A failure costs the search, not the uploadExtraction that fails is logged; the documentation is published either way. Nothing a team can put in an archive can fail their own publication through this path

What comes out is text, and it is treated as text everywhere after: it is indexed, and an excerpt of it is rendered as elements rather than injected as HTML - the same rule the site already followed for uploaded Markdown.

What the doc service is a client of​

Everything above is about who may call the doc service. It calls three services itself: the architecture repository, to read the model it generates the documentation from; - where it is configured - the reaction observer, to read what reacts to what at runtime; and - where it is configured - the Governance Service, to read its reports.

HowA client-credentials token of this service, obtained through JeapOAuth2RestClientBuilderFactory - the jEAP way of calling another service in the system context
Which role<system-name>_@architecture-model_#read for the architecture repository, <system-name>_@reactions_#read for the reaction observer, <system-name>_@governance-documentation_#read for the Governance Service - all without a tenant part, and all granted on that upstream's authorization server rather than this service's own
Configured asjeap.doc.archrepo.environments.<environment>.client-registration, jeap.doc.reactions.environments.<environment>.client-registration and jeap.doc.governance.client-registration, each naming a spring.security.oauth2.client.registration entry
SecretFrom the secret store of the platform. Never in a repository

The reaction observer is read with a token and with nothing else. It also accepts HTTP Basic with an in-memory user, which is what the architecture repository's own importer uses; this service does not, because a second credential model is one more thing to operate and rotate. The consequence is a version floor: the release of the observer that requires a resource server is the one an environment has to be on before it can be configured here.

The doc service reads; neither upstream calls back. There is no inbound surface for this.

A refused token fails the import, not a build: a build makes no call to the architecture repository at all, and what it generates from is what the last successful import stored. So the documentation of an environment goes on being published from the model as of that import - or, where there has never been one, the build is postponed. The message names the client registration and the role, because those are what somebody will have to fix.