Access control¶
Objects and the service info can be read by anyone; access URLs need an
access token of any user, by default (see Requiring login for
reads, also for how to make them public, or
to require login for all reads). Writing, i.e., registering, replacing and
deleting objects and access methods, and posting the service info (see
API),
requires an access token of an OpenID Connect provider that the deployment
trusts (see Authentication), and, for now, the role
admin (see Admins). The identity provider, its claims and the
groups mapped to admin are deployment configuration, without defaults
(see Deployment configuration).
Authentication and access control are implemented with
FOCA, as in
TRS-Filer and
Cloud
Registry;
see the security section of the
configuration.
Work in progress
Access control follows the other registries of ELIXIR On-Cloud step by step:
Authentication¶
Access URLs (GET /objects/{object_id}/access/{access_id}) require an
access token by default, of any user (see Requiring login for
reads). The other read operations (the GET
endpoints), the service info, the API specification
(/ga4gh/drs/v1/openapi.json) and the Swagger UI (/ga4gh/drs/v1/ui/) are
public, and ignore tokens; so are the authorization
info of objects (OPTIONS), which tells clients
which reads need a token, and the passport POST
endpoints, which answer 501. All write
operations of DRS-Filer (POST /objects/register, PUT and DELETE
/objects/{object_id}, DELETE /objects/{object_id}/access/{access_id},
POST /service-info) require an access token of a trusted issuer, sent as
a bearer token (the scheme BearerAuth of the DRS specification):
curl -X POST "http://localhost:8080/ga4gh/drs/v1/objects/register" \
-H "Authorization: Bearer <token>" -H "Content-Type: application/json" \
-d @object.json
Requests without a valid token are rejected with 401 Unauthorized and a
Bearer challenge (WWW-Authenticate: Bearer, RFC 6750; with
error="invalid_token" for invalid tokens), before their body is validated;
requests with a valid token, but without the required role, with 403
Forbidden. Both are problem details.
Tokens are obtained by logging in with the identity provider through an app registered as its client (OpenID Connect), e.g., a portal or gateway, or a client of your own for scripts. DRS-Filer accepts tokens only:
- that are access tokens as per RFC
9068 (
typheaderat+jwt); other tokens, such as ID tokens, are rejected; - of the issuers in
security.auth.issuers(none by default: each deployment sets its identity provider, and the app refuses to start without one); - for the client IDs in
security.auth.audience(theaudclaim), which each deployment sets to the apps that call it (see Configuration); the Docker Compose setup accepts tokens for any audience; - that haven't expired and are signed with a key of the issuer (RS256).
DRS-Filer reads the user's group memberships from the group claim
(security.access_control.claim_groups, needed for the admin
role). Claims in security.auth.userinfo_claims are read from the
identity provider's user info endpoint with the token, for identity
providers that don't put them in access tokens, so the token must be allowed
to release them (e.g., request the corresponding scopes when logging in).
Tokens are validated by
FOCA.
For local development without an identity provider, authentication can be disabled with a config overlay (see Running without authentication); never do this in deployments.
Admins¶
Members of the groups that the deployment maps to the role admin
(security.access_control.group_mapping) are admins: they can do
everything, i.e., register, replace and delete all objects and access
methods, and post the service info. Until objects have owners
(#95), only
admins can write: no policy rule allows writes to other users, who get 403
Forbidden. E.g., with the group claim groups:
The app refuses to start without a group mapped to admin
(security.access_control.require_admin, FOCA), unless a deployment sets
require_admin: false (as the Docker Compose setup does): then nobody can
write. On startup, FOCA logs the groups mapped to admin.
To let other users write, map a group to a role of your own and give the role write rules in a config overlay, e.g., for editors who may register, replace and delete all objects:
security:
access_control:
group_mapping:
drs-admins: admin
drs-editors: editor
policies:
editors-register-objects: [p, editor, /ga4gh/drs/v1/objects/register, POST]
editors-change-objects: [p, editor, "/ga4gh/drs/v1/objects/:object_id", "(PUT)|(DELETE)"]
editors-delete-access-methods: [p, editor, "/ga4gh/drs/v1/objects/:object_id/access/:access_id", DELETE]
Mappings are merged with those of the base config, but group_mapping has
no entries there, so an overlay that sets it lists the admin groups, too.
Rules and FOCA's permissions API can also give roles to single users, named
by their identifier namespaced by issuer (user:<namespace>|<sub>, e.g.,
[g, "user:https://login.example.org/oidc/|alice", admin]), also with a
single trusted issuer; bare users (user:alice) apply to nobody, unless the
issuer keeps its subjects bare with namespace: "" (see User
identifiers).
Group membership changes¶
Group memberships are those of the token: if the group claim is in the
access token, users removed from a group keep its roles, also the role
admin, until the token expires. If it is read from the user info
(security.auth.userinfo_claims), FOCA caches the user info per token for
up to security.auth.cache_ttl seconds (default: 300, but not beyond the
token's expiry; per worker process). So users removed from a group keep its
roles for up to 5 minutes, and users added to a group get them only after
that time (or with a new token). To shorten the delay, lower cache_ttl
(which also sets how long the issuers' discovery documents and keys are
cached), or set security.auth.validate_userinfo: true, which fetches the
user info for every request with a token (and so also rejects revoked
tokens), at the cost of a request to the identity provider each time (see
FOCA's authentication).
Requiring login for reads¶
Access URLs, which may carry credentials (e.g., the headers of an
access_url, or presigned URLs), require login by default, and deployments
can make them public, or require login for all reads, except GET
/service-info. Both use FOCA's spec
patches
and named
entries,
as TRS-Filer does. DRS-Filer ships two patches, which set the security
requirements of read operations to a bearer token (BearerAuth, the
scheme of DRS):
-
drs_filer/api/patches/login-for-access-urls.yaml, for access URLs (GET /objects/{object_id}/access/{access_id}), which the base config applies:# Patch of the API specification (`api.specs.drs`) that requires login for # access URLs (`GetAccessURL`): sets the security requirements of the # operation to a bearer token (`BearerAuth`, the scheme of DRS). Applied by # the base config (`api.specs.drs.patches` in `config.yaml`); objects are # then served without access URLs. Deployments that leave it out of # `patches` make access URLs public. See "Requiring login for reads" in # `docs/access-control.md` paths: "/objects/{object_id}/access/{access_id}": get: security: - BearerAuth: [] -
drs_filer/api/patches/login-for-reads.yaml, for the other reads (GET /objects,GET /objects/{object_id}), which deployments add:# Patch of the API specification (`api.specs.drs`) that requires login for # the reads of objects (`GET /objects`, `GET /objects/{object_id}`), as in # TRS-Filer: sets their security requirements to a bearer token # (`BearerAuth`, the scheme of DRS). Opt-in, in addition to # `login-for-access-urls.yaml`, which covers access URLs; `GET # /service-info` stays public. See "Requiring login for reads" in # `docs/access-control.md` paths: /objects: get: security: - BearerAuth: [] "/objects/{object_id}": get: security: - BearerAuth: []
Requests to the patched reads without a valid token are rejected with 401
Unauthorized (also for objects and access methods that don't exist, so
that their existence doesn't show); any authenticated user may read, by the
default policies (in security.access_control.policies, which are only
evaluated for reads that require login): get-access-urls (GET
/objects/{object_id}/access/{access_id}), list-objects (GET /objects)
and get-objects (GET /objects/{object_id}). GET /service-info, the API
specification (openapi.json) and the Swagger UI (ui/) stay public. The
service info has the number and total size of the objects
(drs.objectCount, drs.totalObjectSize); deployments that require login
for all reads so that not even that shows set custom.stats.enabled:
false (see Service info in the
configuration). The rules allow HEAD too, which Flask serves from the
GET operations and which access control checks as HEAD.
Objects without access URLs¶
Objects carry the access URLs of their access methods, too (access_url).
While access URLs require login, GET /objects and GET
/objects/{object_id} serve objects without them, also to logged-in users
and admins, so that they can't be read without a token through the
objects; the stored objects stay unchanged. Each access method keeps its
access_id (DRS requires one of access_url and access_id), with which
clients get its access URL, with a token:
curl "https://drs.example.org/ga4gh/drs/v1/objects/<object_id>/access/<access_id>" \
-H "Authorization: Bearer <token>"
So, while access URLs require login, an object as GET serves it is no
body for PUT /objects/{object_id}: it would replace the object with one
whose access methods have no access URLs. Build the body from the object as
registered instead.
With public access URLs, objects are served with them, as registered. DRS-Filer reads whether access URLs require login from the specification as patched by all config files, and logs it on startup ("Access URLs need login" or "Access URLs are public").
Public access URLs¶
To make access URLs public, leave the patch out of the patches of the
specification (named drs in the base config) in an overlay. FOCA merges
mappings of overlays into the base config, but replaces lists, so an
overlay that sets patches replaces those of the base config:
With the Helm chart, put the same in the config value. Overlays that set
patches of their own (e.g., to change the info of the specification) must
list api/patches/login-for-access-urls.yaml too, or access URLs become
public: check the startup log.
Login for all reads¶
To require login for all reads, list both patches in an overlay (the paths are relative to the directory of the base config, where the patches are installed):
api:
specs:
drs:
patches:
- api/patches/login-for-access-urls.yaml
- api/patches/login-for-reads.yaml
With only api/patches/login-for-reads.yaml, objects require login, but
access URLs are public, and objects are served with them.
Readers¶
To allow reads for some users only, replace the rules by name in an
overlay, e.g., with rules for a role that a group is mapped to, in addition
to the deployment's admin groups (null removes a rule; admins may always
read):
security:
access_control:
group_mapping:
drs-admins: admin
drs-readers: reader
policies:
get-access-urls: [p, reader, "/ga4gh/drs/v1/objects/:object_id/access/:access_id", "GET|HEAD"]
list-objects: [p, reader, /ga4gh/drs/v1/objects, "GET|HEAD"]
get-objects: [p, reader, "/ga4gh/drs/v1/objects/:object_id", "GET|HEAD"]
The rules only apply to the reads that require login: with the default
patches, list-objects and get-objects have no effect, and objects stay
public. If an overlay of the deployment gives the policies as a list, which
replaces the rules of the base config, add these rules to the list (FOCA
refuses named rules after a list).
With great power comes great responsibility
Patches and rules in overlays can weaken or remove authentication and access control as easily as they add them. Review them like code, keep them as small as possible, and check the startup logs, which list the applied patches, say whether access URLs need login, and warn of operations that patches make public (see FOCA's patching specifications).
Authorization info¶
Clients can find out how to authorize their reads before they send them
(DRS's Authorizations), from the same security requirements of the
patched specification that DRS-Filer enforces (see Requiring login for
reads); so the answers change with the
patches, and match what the served specification (openapi.json) says:
- Objects (
GET /objects/{object_id}):OPTIONS /objects/{object_id}answers with the authorization info of the object, andOPTIONS /objectswith that of several objects (bulk_object_idsin the request body). Both are public, and take no token. - Access URLs (
GET /objects/{object_id}/access/{access_id}): each access method of the objects thatGET /objectsandGET /objects/{object_id}serve has the authorization info of its access URL (authorizations), if it has anaccess_id.
While a read requires login, its authorization info lists bearer tokens
(BearerAuth) of the trusted issuers (bearer_auth_issuers, those of
security.auth.issuers); otherwise no authorization (None). E.g., with
the default patches, objects are public and access URLs need login:
$ curl -X OPTIONS "https://drs.example.org/ga4gh/drs/v1/objects/<object_id>"
{"drs_object_id": "<object_id>", "supported_types": ["None"]}
$ curl "https://drs.example.org/ga4gh/drs/v1/objects/<object_id>"
{..., "access_methods": [{"type": "https", "access_id": "<access_id>",
"authorizations": {"supported_types": ["BearerAuth"],
"bearer_auth_issuers": ["https://login.example.org/oidc/"]}, ...}], ...}
With login for all reads, OPTIONS lists
BearerAuth too, and with public access URLs,
access methods list None. The authorization info says which token a read
needs, not whether the user may read: with rules for
readers, the tokens of other users get 403 Forbidden.
The authorization info never lists passports (PassportAuth,
passport_auth_issuers) or basic authentication (BasicAuth), which
DRS-Filer doesn't accept (see Passport POST
endpoints).
While object reads require login, OPTIONS answers the same for every
identifier, whether an object exists or not, so that anonymous clients
can't find out which objects exist; they get 404 (or 401) only from the
reads, with a token. While object reads are public, OPTIONS
/objects/{object_id} answers 404 Not Found for unknown objects, and
OPTIONS /objects lists them under unresolved_drs_objects, with
error_code 404:
$ curl -X OPTIONS "https://drs.example.org/ga4gh/drs/v1/objects" \
-H "Content-Type: application/json" \
-d '{"bulk_object_ids": ["<object_id>", "unknown"]}'
{"summary": {"requested": 2, "resolved": 1, "unresolved": 1},
"unresolved_drs_objects": [{"error_code": 404, "object_ids": ["unknown"]}],
"resolved_drs_object": [{"drs_object_id": "<object_id>", "supported_types": ["None"]}]}
OPTIONS /objects answers each identifier once, in the order of the
request, and counts distinct identifiers in its summary. It takes at most
custom.bulk.max_request_length identifiers (100 by default, counted as
sent, duplicates too; see Service info in
the configuration), the maxBulkRequestLength of the service info; requests
with more get 413 Payload Too Large, and requests without
bulk_object_ids 400 Bad Request. CORS preflight requests (OPTIONS
with Origin and Access-Control-Request-Method) don't get the
authorization info, but Flask's answer for CORS (see Deviations from the
specification).
Network access¶
Authentication applies to every request that reaches the app, also from
inside the cluster; to keep FOCA's permissions API (/admin/access-control/,
for admins only) off the internet, see Access.