.gitbay/wiki/Architecture/06-Data-and-Cryptography.org

545ba0bcdea3b534903bd78c918c0c025a97eda7
gitbay/.gitbay/wiki/Architecture/06-Data-and-Cryptography.org

121 lines · 9365 bytes

6 symbols in this file
  1#+title: Data and cryptography
  2
  3* Data inventory
  4
  5Schema: =internal/store/migrations/=, 66 migrations. Classification:
  6*C* credential or secret, *P* personal data, *R* private repository
  7content (as confidential as the repository), *O* operational.
  8
  9| Domain          | Tables                                                                                      | Class | Notes                                           |
 10|-----------------+---------------------------------------------------------------------------------------------+-------+-------------------------------------------------|
 11| Identity        | =users=, =emails=, =ssh_keys=, =pgp_keys=, =orgs=, =org_members=, =teams=, =team_members=   | P     | email addresses in clear; keys are public       |
 12| Credentials     | =api_tokens=, =web_sessions=, =login_tokens=, =email_tokens=, =invites=                    | C     | SHA-256 hashes only                              |
 13| Repositories    | =repos=, =repo_access=, =team_repos=, =repo_topics=, =repo_watchers=, =repo_pins=, =repo_bookmarks=, =page_domains= | O |                                  |
 14| Collaboration   | =issues=, =issue_*=, =merge_requests=, =mr_*=, =labels=, =milestones=, =mentions=           | R     | bodies of issues, comments and reviews          |
 15| Releases, snippets | =releases=, =release_assets=, =snippets=, =snippet_files=                                | R     |                                                 |
 16| CI              | =builds= (includes logs), =build_schedules=, =runner_repos=, =runner_seen=                  | R     | build logs can echo anything a step prints      |
 17| CI secrets      | =build_secrets=                                                                             | C     | sealed (AES-256-GCM)                            |
 18| Integrations    | =webhooks= (secret), =webhook_deliveries=, =mirrors= (username, token)                      | C     | webhook secret and mirror token sealed          |
 19| Notifications   | =notifications= (mail queue), =inbox=, =push_devices= (APNs token), =push_queue=, =mail_replies= (Message-IDs of posted replies) | P     | device tokens sealed; looked up by SHA-256      |
 20| Signatures      | =commit_signatures=, =settings.key_epoch=                                                   | O     | verification cache                              |
 21| Audit and feed  | =audit_log=, =events=                                                                       | O, P  | actor ids, pruned argv, fingerprints and IPs in some audit rows, a hash chain (=prev_hash=, =hash=) |
 22| Dependencies    | =dep_checks=, =dep_reports=, =dep_advisories=, =dep_advisory_dismissals=                    | O     |
 23| Code scanning   | =security_scans=, =security_findings=, =security_dismissals=                                | O     |                                                 |
 24
 25Outside the database:
 26
 27| Data                       | Location                          | Class |
 28|----------------------------+-----------------------------------+-------|
 29| Repository contents        | =<root>/repos=                    | R     |
 30| LFS objects                | =<root>/lfs=                      | R     |
 31| SSH host key               | =<root>/ssh/host_ed25519=         | C     |
 32| TLS keys (ACME)            | =<root>/acme=                     | C     |
 33| SMTP password              | =/etc/gitbay/config.toml=         | C     |
 34| APNs signing key (.p8)     | path in =push.key_file=           | C     |
 35| IMAP password              | path in =mail.inbound.password_file= | C  |
 36| Secret key file            | =server.secret_key_file= (=/etc/gitbay/secret.key=) | C |
 37| Backups                    | =/var/backups/gitbay=, offsite    | all of the above |
 38
 39No table stores client IP addresses as a column. The daemon writes a
 40client IP into an audit row only for authentication failures and
 41throttling (=internal/sshd/sshd.go=).
 42
 43* At rest
 44
 45| Item                                  | Protection                                                     |
 46|---------------------------------------+----------------------------------------------------------------|
 47| API tokens, sessions, login links, email codes, invites | SHA-256 of a 256-bit random value; the value is shown once and never stored (=internal/store/sessions.go=) |
 48| CI secrets, webhook secrets, mirror tokens, APNs device tokens | AES-256-GCM under a key file outside the database and outside =server.root=; additional data binds table, column and row (=internal/seal=, =internal/store/secrets.go=) |
 49| SQLite file                           | mode 0640, directory 0750                                      |
 50| Backups                               | local archives age-encrypted when =[backup] age_recipients= is set; restic encrypts the offsite copy; neither carries the secret key file, which is copied off the host by hand until a separate keys repository is set up |
 51| Disk                                  | no application-level encryption; any disk encryption is the host's |
 52
 53The database file or a backup read by anyone other than the =gitbay=
 54user discloses no CI secret, webhook secret, mirror token or device
 55token without the key file, which neither carries. Rotation:
 56=gitbayd admin secrets rotate= (Admin wiki).
 57
 58* In transit
 59
 60| Channel                  | Protection                                                   |
 61|--------------------------+--------------------------------------------------------------|
 62| SSH                      | Go =x/crypto/ssh=; ed25519 host key generated on first start |
 63| HTTPS                    | TLS 1.2 minimum (=cmd/gitbayd/tls.go=), ACME or operator certificates; HSTS one year |
 64| HTTP port 80             | ACME challenges and redirect only                            |
 65| git://                   | none (public data only; off by default)                      |
 66| Runner ↔ server          | SSH                                                           |
 67| SMTP                     | STARTTLS required unless the relay is local (=mail.require_tls=), or implicit TLS (=mail.tls=) |
 68| APNs                     | TLS, HTTP/2                                                  |
 69| IMAP                     | implicit TLS or STARTTLS, TLS 1.2 minimum, certificate verified (=internal/imapc=) |
 70| Webhooks                 | TLS when the URL is https; HMAC-SHA256 body signature in =X-Gitbay-Signature-256= (=internal/webhook/webhook.go=) |
 71| Mirrors                  | per URL; token passed through =GIT_ASKPASS=, never argv (=internal/mirror/mirror.go=) |
 72
 73TLS 1.2 is the minimum, set in code (=serverTLS= in
 74=cmd/gitbayd/tls.go=); cipher suites are Go's defaults.
 75
 76* Cryptographic primitives
 77
 78| Use                             | Primitive                                  | Code                               |
 79|---------------------------------+--------------------------------------------+------------------------------------|
 80| Token generation                | =crypto/rand=, 32 bytes                    | =internal/store/sessions.go=    |
 81| Token storage                   | SHA-256                                    | =sessions.go=                   |
 82| LFS transfer tokens             | HMAC-SHA256, secret in =settings=          | =internal/lfs/lfs.go=      |
 83| Webhook signatures              | HMAC-SHA256                                | =internal/webhook/webhook.go=  |
 84| APNs provider token             | ES256 JWT (ECDSA P-256)                    | =internal/push/token.go=           |
 85| SSH host key                    | ed25519                                    | =internal/sshd/sshd.go=     |
 86| Commit and tag signatures       | verify OpenPGP (ProtonMail go-crypto) and SSHSIG | =internal/sig=               |
 87| LFS object ids                  | SHA-256                                    | =internal/lfs/lfs.go=           |
 88
 89Signature verification results are cached in =commit_signatures= with
 90the global =key_epoch= at the time of verification. Any change to a
 91trust input (a key added or removed, an email verified) bumps the
 92epoch, which invalidates every cached result (=internal/store/users.go=,
 93=internal/control/sig.go=).
 94
 95The server holds no signing key and signs nothing. A "verified" badge
 96means a user's own key signed the commit.
 97
 98* Secret handling rules
 99
100- Secrets enter only on stdin. A command must set =ReadsStdin=
101  to receive stdin at all; =TestStdinCommandsReadStdin= enforces it.
102  Examples: =repo secret set=, =repo deploy-key add=, =repo import
103  --token-stdin= (=internal/control/build.go=, =import.go=).
104- Secrets are listed by name, never echoed back.
105- The audit log stores argv with flag values stripped
106  (=internal/control/control.go=).
107- Mail errors are logged with addresses redacted
108  (=internal/notify/notify.go=).
109- CI secrets travel in the runner's claim only for trusted builds and
110  reach the container as environment variables through a 0600 env file
111  or podman's =--env NAME= pass-through, never argv
112  (=cmd/gitbay-runner/isolate.go=).
113
114* Retention
115
116Configured under =[retention]= for =audit=, =events=,
117=webhook_deliveries=, =mail= and =push=; unset means keep forever.
118Expired sessions and tokens are swept hourly regardless
119(=internal/config/config.go=, =cmd/gitbayd/main.go=).
120Accounts that never verify are removed after
121=registration.pending_expiry=. =account export= gives a user their data.