26.39. kych-oauth2-gateway(1)#

26.39.1. Name#

kych-oauth2-gateway - OAuth 2.0 gateway for electronic identification

26.39.2. Synopsis#

kych-oauth2-gateway [-c FILE] [-L LEVEL] [-v]

kych-oauth2-gateway [-h | -V]

26.39.3. Description#

kych-oauth2-gateway is an HTTP server that lets an OAuth 2.0 client - typically a GNU Taler exchange performing KYC - obtain identity attributes from the Swiss SWIYU e-ID trust infrastructure.

Towards the client it speaks a plain OAuth 2.0 authorization code flow. Towards the SWIYU verifier it speaks OpenID for Verifiable Presentations (OID4VP): it builds a DCQL query, has the user’s SWIYU wallet present an SD-JWT verifiable credential against it, and hands the disclosed claims back to the client. The OAuth 2.0 scope of the authorization request names the credential claims to disclose, which is what makes the disclosure selective: a client that only needs proof of majority requests the scope age_over_18, and learns nothing else.

The gateway does not verify credentials itself and holds no signing keys. All cryptographic verification happens in the SWIYU verifier that kych.conf(5) points each client at; the gateway keeps the session state, mints the OAuth 2.0 codes and tokens, and stores the wallet’s response until the client collects it. Every PURGE_INTERVAL it deletes the claims and the evidence PURGE_GRACE after the client first fetched them, and the sessions, codes and tokens that have expired; see kych.conf(5).

Its options are as follows:

-c FILE | –config=FILE

Read the configuration from FILE. Without it the standard search path applies, ending at /etc/kych/kych.conf. See kych.conf(5).

-L LEVEL | –log=LEVEL

Set the logging verbosity. Accepted values are ERROR, WARN, INFO, DEBUG and TRACE, or the numbers 1 to 5; case is ignored. Defaults to INFO. An unrecognised value is refused before the server starts.

Note

At DEBUG the log includes the generated nonces, authorization codes and the full request bodies exchanged with the verifier. Such logs contain both secrets and personal data.

-v | –verbose

Also log what the libraries have to say. Without it, messages from sqlx, axum, hyper, h2, reqwest, rustls and mio are dropped whatever -L says, which is what keeps DEBUG readable.

-h | –help

Print short help on options and exit.

-V | –version

Print version information and exit.

Each line of the log carries a timestamp with the machine’s UTC offset, the level, the source and, for anything logged while handling a request, a random ten-character identifier of that request in parentheses - which is how the several lines belonging to one verification can be told apart under load. Under systemd the timestamp is omitted, since the journal records its own.

26.39.4. Endpoints#

The server exposes the following HTTP endpoints. The REST API is specified in detail in the KyCH OAuth2 Gateway RESTful API documentation; the summary here is limited to what an administrator needs in order to place the service behind a reverse proxy.

GET /config

Public. Lists every enabled vocabulary – its kind, format, credential types and claims – and every profile, with the required and optional claims of each of its lines. The older vc_* members report the credential type, format, algorithms and claims of the first enabled SD-JWT VC vocabulary, as configured by VCT, FORMAT, ALGORITHMS and CLAIMS.

POST /setup/{client_id}

Authenticated with the client secret as an HTTP bearer token. Opens a verification session and returns its nonce, the unguessable part of the authorization URL handed to the user, and when it expires: 15 minutes later. An optional JSON body, possibly sent with Content-Encoding: deflate as the Taler exchange does, may fix the session’s vocabulary and profile.

GET /authorize/{nonce}

Entered by the user’s browser. Takes the OAuth 2.0 parameters response_type (which must be code), client_id, redirect_uri, state and scope as query arguments, starts the verification at the helper the session’s vocabulary names (the SWIYU verifier, say) and returns the wallet’s verification URL. With an Accept header naming text/html the reply is a page showing a QR code and a wallet deep link, in English, German or French as Accept-Language asks, or, for the German eID card and eIDAS, a redirect to the helper; otherwise it is JSON.

The redirect_uri must appear in the client’s registered allowlist, and scope must name either one of the client’s profiles or claims of its vocabulary that are permitted, or the request is refused. If the profile covers several of the client’s vocabularies and none is fixed, the reply is instead a page (or JSON) letting the person choose; the choice is posted back to the same URL, POST /authorize/{nonce}. The session records its vocabulary and helper, and finishes there even if the configuration changes meanwhile. Re-entering the URL replays the existing verification instead of starting a second one.

POST /notification

Unauthenticated webhook, called by a helper (the SWIYU verifier) when a wallet has responded. The gateway then fetches the result from that helper itself, stores the disclosed credential with the evidence of how it was checked, and mints the authorization code. It answers 200 OK in all cases, including every failure, so that the helper does not retry; problems are visible only in the log.

GET /status/{verification_id}

Polled by the browser during verification, authorised by the OAuth 2.0 state value as a query argument. Reports pending, authorized, verified, completed, failed or expired. For a helper without a webhook, such as the EUDI verifier, the gateway asks the helper for the outcome here, at most once a second per session.

GET /return/{verification_id}

Where a helper that the browser itself went through – the eID server, the eIDAS connector – sends the person back. The gateway asks the helper for the outcome and continues to /finalize, also when the verification failed or expired; it shows that itself only when the client’s redirect_uri is no longer registered.

GET /finalize/{verification_id}

Also authorised by state. Redirects the browser back to the client’s redirect_uri with the authorization code, once the session is verified, or with error=access_denied, error_description and state (RFC 6749, section 4.1.2.1) once it failed or expired; the wallet page sends the browser here in either case. The redirect_uri must still be one the client has registered.

POST /token

The OAuth 2.0 token endpoint, form-encoded, authenticated with client_id and client_secret. Exchanges the authorization code for a bearer token valid for one hour. The code is single-use, and the redirect_uri must match the one used at authorization time.

GET /info

Authenticated with the bearer token from /token. Returns the disclosed claims as JSON, under their native names, and beside them vocabulary (which source of identity was used), missing (the profile’s optional claims the credential did not have) and evidence (how the result was obtained and checked, including the raw presentation where the helper hands it out). Once these are purged, it answers 410 Gone with claims_purged.

26.39.5. Environment#

LISTEN_FDS, LISTEN_PID

Read when SERVE = systemd: the listening socket is taken from the service manager instead of being bound. Ignored otherwise.

JOURNAL_STREAM

Set by systemd. Its presence suppresses the timestamp on each log line, because the journal already records one.

XDG_CONFIG_HOME, HOME

Searched for a configuration file when -c is not given, and expanded in options that name a path. $PATH is searched for the kych-oauth2-gateway binary itself, to derive $PREFIX and the other variables of the [paths] section.

PGHOST, PGPORT, PGUSER, PGPASSWORD, PGDATABASE, PGSSLMODE

Supply defaults for any part that the DATABASE connection string leaves out. Note that ~/.pgpass is not consulted when DATABASE is given in URI form, which it normally is.

26.39.6. Files#

/etc/kych/kych.conf

Configuration file, as installed by the Debian package, and the last of the four locations searched when -c is not given. See kych.conf(5).

/usr/share/kych/config.d/

Read before the configuration file itself, so that packaged defaults can be overridden rather than edited.

./js/

The QR code helper served under the /js URL prefix is read from a path relative to the working directory of the process, not from an installed location. Start the server from the directory that holds js/ - the packaged systemd unit uses /usr/share/kych - or the authorization page will render without its QR code.

/run/kych/kych.sock

Listening socket of the packaged service: created by the server itself per UNIXPATH with the shipped SERVE = unix, or by kych.socket with SERVE = systemd. Mode 0660, group kych-api: the reverse proxy (www-data) and KyCH’s local clients (Beekeeper’s lookup worker) are its members. The server runs with that group as its primary group and with kych (its configuration) and www-data (the EUDI and walt.id verifiers’ sockets) as supplementary groups.

26.39.7. Security#

The server speaks plain HTTP and never terminates TLS; run it behind a reverse proxy. It performs no privilege separation, so run it as an unprivileged user. Give its Unix socket a group of its own (kych-api in the Debian package), shared only with the proxy and KyCH’s local clients, not the group of the helpers’ sockets, whose management APIs are unauthenticated.

Access control differs per endpoint, and none of it is a substitute for a proxy that restricts who may reach what. In particular /notification accepts unauthenticated requests and should be reachable only from the verifier’s address, while /status and /finalize are protected merely by knowledge of the OAuth 2.0 state value.

26.39.8. Exit Status#

On SIGINT or SIGTERM the server stops accepting connections, lets the requests it is already handling finish, and exits zero. It exits non-zero before serving any request if the configuration cannot be read or is incomplete (for instance if SERVE = unix without a UNIXPATH), if the database is unreachable, or if the listening socket cannot be bound.

26.39.9. Examples#

Start the server with a configuration file:

$ kych-oauth2-gateway -c /etc/kych/kych.conf

Start the server with debug logging enabled:

$ kych-oauth2-gateway -c /etc/kych/kych.conf -L DEBUG

26.39.10. See Also#

kych-client-management(1), kych.conf(5).

The KyCH operator manual, https://docs.taler.net/taler-kych-manual.html, and the REST API specification, https://docs.taler.net/core/api-kych.html.

26.39.11. Bugs#

Report bugs by using https://bugs.taler.net/ or by sending electronic mail to <taler@gnu.org>.