Aller au contenu principal

members

Role: owns the member profiles. It provisions every new member a Google Workspace account and a Keycloak user linked to that Google identity (the Keycloak ID is the member ID), handles departures, crypto-shredding erasure, customisable statuses, yearly membership terms, board mandates, trainings and the member timeline. The member aggregate and training data are event sourced (see CQRS).

Limits: no authentication (the gateway does it) and no authorization decision (it asks authz). It never deletes Workspace accounts, only suspends them. Trainings are indicative: nothing locks a tool. History entries for projects and events are not implemented yet (sources are pluggable).

Provisioning​

POST /v1/members (and each CSV import line) runs these steps, recorded in a provisionings document whose PII is sealed with its own key (subject provisioning:<id>):

  1. Choose the address first.last@GOOGLE_DOMAIN (accents folded, other characters dropped; membre if the first name is empty), then first.last2, first.last3… up to 20, skipping addresses used in MongoDB or in Workspace. Otherwise 409 workspace_email_unavailable.
  2. Create the Workspace user (random initial password, change required at next login, personal e-mail as recovery address). An existing account with the same address is reused.
  3. Create the Keycloak user (username = e-mail, e-mail verified, no password) and link it to the Google identity (KEYCLOAK_GOOGLE_IDP_ALIAS). Both are idempotent.
  4. Create the member (event members.member.created, source provisioning), open the current term, delete the provisioning record and shred its key.

Success returns 201 with the member and workspace_initial_password (shown once). A failed step returns 202 with the provisioning (state: provisioning_failed, error: workspace_failed, keycloak_failed, keycloak_link_failed or store_failed, attempts); POST /v1/members/provisionings/:id/retry resumes after the completed steps. Without GOOGLE_* / KEYCLOAK_* settings, logging fakes are used (refused in production).

Members can also appear without provisioning: GET /v1/members/me creates a minimal profile at first login (source first_login, names from Keycloak, or Membre #<8 chars>), and POST /v1/members/sync/:id creates or refreshes a member from its Keycloak account (source sync). The Workspace address is only kept when it belongs to GOOGLE_DOMAIN.

Profile and privacy​

  • Validation: names 1–64 characters, display name ≤ 64, pronouns ≤ 32, locale fr/en (default fr), YYYY-MM-DD birth date after 1900 and in the past, poles among tech, bike, textile, mechanics, printing_3d, communication, at most 20 site IDs matching ^[a-z0-9][a-z0-9_-]{0,63}$.
  • Private fields (personal_email, phone, birth_date) are sealed at rest and returned only to the member or with members.member.read_private (?private=true, audited). Names, pronouns and the Workspace address are stored in clear in the state document (search index) but sealed in events. See encryption.
  • A member may patch their own profile except first_name, last_name, poles, site_ids (needs members.member.update).
  • Search (q): up to 5 accent-folded word prefixes, all required, matched against search_terms.
  • Directory: GET /v1/members/directory?q=&ids= returns only id, display_name and avatar_key of non-deleted, non-erased members, for pickers and invitee names (event invitations). Any authenticated user may call it without a grant; API keys and services need members.member.read and only see their read scope. ids is a comma list (max 100); pages are capped at 50. Not audited (no sensitive field).
  • GET /v1/members/me/export: GDPR export of the caller (profile, terms, mandates, trainings without validator IDs, history), my-data.json, audited.

Departure and erasure​

StepTriggerEffect
DepartureDELETE /:id (members.member.delete)Workspace suspended, Keycloak user disabled, deleted_at and purge_at = now + MEMBER_PURGE_DELAY; hidden from lists
RestorePOST /:id/restore (members.member.delete)Accounts reactivated, dates cleared; refused once erased
Erasurepurge job, or DELETE /:id?force=true (members.member.force_delete)Workspace suspended (if still active), Keycloak user deleted, member key shredded, state replaced by a stub Ancien membre #<8 chars>

The stub keeps ID, status and dates so other services' references still resolve. Terms, mandates, trainings and role history are kept (no PII). Event members.member.erased carries forced; authz consumes it. Provider errors return 503 unavailable and nothing changes.

Membership​

  • Statuses: customisable (key matching ^[a-z][a-z0-9_]{1,31}$, immutable; label, label_en, auto_renew, position). Seeded at startup if missing: active, board, honorary (auto-renew), alumni, inactive. A status assigned to a member cannot be deleted (409 status_in_use). New members get MEMBER_DEFAULT_STATUS.
  • Terms: one per member and school year (starting MEMBERSHIP_TERM_START_MONTH), with the status and a source join or renewal. Opened at creation; never removed.
  • Mandates: board positions (position ≤ 64, starts_on, optional ends_on ≥ starts_on, YYYY-MM-DD).
  • Trainings: types (name, description, tool and category IDs referencing inventory, validity_days 0–3650 with 0 = no expiry, optional site). Deleting a type is a soft delete. One validation per member and type; validating again renews it; validated_at may be back-dated but not in the future. GET /trainings/expiring?within=720h lists active validations expiring soon (default 30 days, max 366 days).
  • History: GET /:id/history merges member events (member_created, profile_updated, status_changed, member_deleted, member_restored, member_erased), terms, mandates, training validations/revocations and role assignments (role_assigned, role_unassigned), newest first, at most 1000 items per source.
  • Bulk: POST /bulk applies update (status, poles, site IDs), delete or restore to up to 200 IDs, authorizing and reporting each member separately.
  • CSV: import and export, see CSV formats.

Scheduled jobs​

Both run on every replica, guarded by a MongoDB lease (locks collection) so only one executes at a time.

JobIntervalWork
members-purgeMEMBER_PURGE_INTERVALErase up to 500 members whose purge_at has passed
members-renewalMEMBERSHIP_RENEWAL_INTERVALOpen the current term of non-deleted members whose status has auto_renew (idempotent)

Dependencies​

  • Services: authz (ConnectRPC Check, LookupResources through authzclient).
  • Infrastructure: MongoDB (replica set, transactions), Kafka, Google Workspace Admin SDK (Directory API, domain-wide delegation), Keycloak Admin REST API (client credentials), KEK source (env or OpenStack Barbican).
  • Libraries: authzclient, cryptox, csvx, eventstore, outbox, lease, kafkax, mongox, httpx, pagination, principal, problem, audit, arn, ids, config, logging, telemetry (see libraries).

Inputs and outputs​

KindNameNotes
HTTP/v1/members/*profiles, provisionings, statuses, terms, mandates, trainings, history, bulk, CSV; API reference
RPC outauthz.v1.AuthzService/Check, LookupResourcesevery decision; list scopes
HTTP outGoogle Admin SDK, Keycloak Admin APIprovisioning, suspension, erasure
Kafka outmembers.member.v1created, updated (changed fields), status_changed, deleted (purge_at), restored, erased (forced); PII values sealed
Kafka outmembers.training.v1type_created, type_updated, type_deleted, validated, revoked (IDs and dates only)
Kafka outaudit.records.v1members.member.create/update/status_change/delete/restore/erase, members.member.read_private, members.member.export, members.member.gdpr_export, members.provisioning.create/retry, members.status.create/update/delete, members.term.create, members.mandate.create/update/delete, members.training.create/update/delete/validate/revoke
Kafka inauthz.assignment.v1created / deleted for user subjects → role_history (consumer group members)

Events and audit records are written to the outbox in the same transaction as the state and relayed to Kafka (see Kafka). Event key = aggregate ID.

Data (MongoDB, database members)​

CollectionContentIndexes
membersmember state: names, display name, workspace_email, workspace_user_id, sealed private fields, pronouns, locale, poles, site IDs, status, avatar key, search_terms, deleted_at, purge_at, erased_at, versionworkspace_email unique (partial), purge_at (partial), (search_terms, _id), (status, _id), (poles, _id), (site_ids, _id), (deleted_at, _id)
provisioningspending / failed creations: sealed PII and initial password, step IDs, error, attemptsworkspace_email unique
statusesstatuseskey unique
membership_termsmember ID, year, bounds, status, source(member_id, year) unique, (year, _id)
mandatesmember ID, position, dates(member_id, _id)
training_typestraining types (soft deleted)(deleted_at, _id)
training_validationsmember ID, training ID, validator, dates, revocation(member_id, training_id) unique, (expires_at, _id)
role_historyprojection of authz assignments (ID = event ID)(member_id, at)
eventsevent store (member, training type, validation aggregates)from eventstore
data_keyswrapped per-member and per-provisioning data keysfrom cryptox
outbox, locksoutbox messages, relay and job leasesfrom outbox / lease

Configuration​

VariableDefaultDescription
HTTP_ADDR:8082Listen address
PRINCIPAL_PUBLIC_KEYrequiredVerifies X-Atl-Principal
AUTHZ_URLhttp://localhost:8081authz ConnectRPC endpoint
KAFKA_BROKERSlocalhost:19092Outbox relay and authz.assignment.v1 consumer
MONGO_URImongodb://localhost:27017/?directConnection=trueMongoDB (replica set required)
MONGO_DATABASEmembersDatabase name
CRYPTO_KEK_SOURCEenvenv or barbican
CRYPTO_KEKrequired with envBase64 AES key encrypting the data keys
OS_AUTH_URL, OS_APPLICATION_CREDENTIAL_ID, OS_APPLICATION_CREDENTIAL_SECRETrequired with barbicanOpenStack credentials
OS_REGION_NAMEemptyOpenStack region
CRYPTO_KEK_BARBICAN_SECRET_IDrequired with barbicanBarbican secret holding the KEK
GOOGLE_SA_JSON_FILE, GOOGLE_ADMIN_SUBJECTemptyService account key file and admin to impersonate; both enable Workspace
GOOGLE_DOMAINatelier-maker.frWorkspace domain of member addresses
KEYCLOAK_URL, KEYCLOAK_CLIENT_ID, KEYCLOAK_CLIENT_SECRETemptyAdmin API client; all three enable Keycloak
KEYCLOAK_REALMatelierRealm
KEYCLOAK_GOOGLE_IDP_ALIASgoogleGoogle identity provider alias
MEMBER_PURGE_DELAY360h (15 days)Departure to erasure delay (not negative)
MEMBER_PURGE_INTERVAL1hPurge job interval
MEMBERSHIP_RENEWAL_INTERVAL6hRenewal job interval
MEMBERSHIP_TERM_START_MONTH9First month of the school year (1–12)
MEMBER_DEFAULT_STATUSactiveStatus of new members

Workspace and Keycloak must both be configured when APP_ENV=production.

Plus the common APP_ENV, LOG_LEVEL, METRICS_ADDR, OTEL_EXPORTER_OTLP_ENDPOINT (see environment variables).