SelfPrivacy API
API available as Swagger documentation, markdown version is below.
Version
1.2.0
Content negotiation
URI Scheme: http
Consumes: application/json
Produces: application/json
Access control
- bearerAuth
All endpoints
backups
Method | URI | Name | Summary |
---|---|---|---|
GET | /services/restic/backup/list | get services restic backup list | Get all restic backups |
GET | /services/restic/backup/reload | get services restic backup reload | Force reload snapshots |
GET | /services/restic/backup/status | get services restic backup status | Get backup status |
PUT | /services/restic/backblaze/config | put services restic backblaze config | Set the new key for backblaze |
PUT | /services/restic/backup/create | put services restic backup create | Initiate a new restic backup |
PUT | /services/restic/backup/restore | put services restic backup restore | Start backup restoration |
bitwarden
Method | URI | Name | Summary |
---|---|---|---|
POST | /services/bitwarden/disable | post services bitwarden disable | Disable Bitwarden |
POST | /services/bitwarden/enable | post services bitwarden enable | Enable Bitwarden |
Method | URI | Name | Summary |
---|---|---|---|
GET | /services/mailserver/dkim | get services mailserver dkim | Get DKIM key from file |
gitea
Method | URI | Name | Summary |
---|---|---|---|
POST | /services/gitea/disable | post services gitea disable | Disable Gitea |
POST | /services/gitea/enable | post services gitea enable | Enable Gitea |
nextcloud
Method | URI | Name | Summary |
---|---|---|---|
POST | /services/nextcloud/disable | post services nextcloud disable | Disable Nextcloud |
POST | /services/nextcloud/enable | post services nextcloud enable | Enable Nextcloud |
ocserv
Method | URI | Name | Summary |
---|---|---|---|
POST | /services/ocserv/disable | post services ocserv disable | Disable OCserv |
POST | /services/ocserv/enable | post services ocserv enable | Enable OCserv |
pleroma
Method | URI | Name | Summary |
---|---|---|---|
POST | /services/pleroma/disable | post services pleroma disable | Disable Pleroma |
POST | /services/pleroma/enable | post services pleroma enable | Enable Pleroma |
services
Method | URI | Name | Summary |
---|---|---|---|
GET | /services/status | get services status | Get service status |
ssh
Method | URI | Name | Summary |
---|---|---|---|
DELETE | /services/ssh/keys/{username} | delete services SSH keys username | Delete SSH key |
GET | /services/ssh | get services SSH | Get current SSH settings |
GET | /services/ssh/keys/{username} | get services SSH keys username | List SSH keys |
POST | /services/ssh/enable | post services SSH enable | Enable SSH |
POST | /services/ssh/keys/{username} | post services SSH keys username | Add SSH key to the user |
PUT | /services/ssh | put services SSH | Change SSH settings |
PUT | /services/ssh/key/send | put services SSH key send | Add a SSH root key |
system
Method | URI | Name | Summary |
---|---|---|---|
GET | /api/version | get API version | Get API version |
GET | /system/configuration/apply | get system configuration apply | Rebuild NixOS with nixos-rebuild switch |
GET | /system/configuration/autoUpgrade | get system configuration auto upgrade | Get current system autoupgrade settings |
GET | /system/configuration/pull | get system configuration pull | Pull Repository Changes |
GET | /system/configuration/rollback | get system configuration rollback | Rollback NixOS with nixos-rebuild switch --rollback |
GET | /system/configuration/timezone | get system configuration timezone | Get current system timezone |
GET | /system/configuration/upgrade | get system configuration upgrade | Upgrade NixOS with nixos-rebuild switch --upgrade |
GET | /system/pythonVersion | get system python version | Get python version used by this API |
GET | /system/reboot | get system reboot | Reboot the system |
GET | /system/version | get system version | Get system version from uname -a |
PUT | /system/configuration/autoUpgrade | put system configuration auto upgrade | Change system auto upgrade settings |
PUT | /system/configuration/timezone | put system configuration timezone | Change system timezone |
tokens
Method | URI | Name | Summary |
---|---|---|---|
DELETE | /auth/tokens | delete auth tokens | Delete token |
GET | /auth/recovery_token | get auth recovery token | Get recovery token status |
GET | /auth/tokens | get auth tokens | Get current device tokens |
POST | /auth/new_device | post auth new device | Get new device token |
POST | /auth/new_device/authorize | post auth new device authorize | Authorize device |
POST | /auth/recovery_token | post auth recovery token | Generate recovery token |
POST | /auth/recovery_token/use | post auth recovery token use | Use recovery token |
POST | /auth/tokens | post auth tokens | Refresh token |
users
Method | URI | Name | Summary |
---|---|---|---|
DELETE | /users/{username} | delete users username | Delete a user |
GET | /users | get users | Get a list of users |
POST | /users | post users | Create a new user |
Paths
Delete token (DeleteAuthTokens)
DELETE /auth/tokens
Security Requirements
- bearerAuth
Parameters
Name | Source | Type | Required | Default | Description |
---|---|---|---|---|---|
token | body | DeleteAuthTokensBody | ✓ | Token's name to delete |
All responses
Code | Status | Description |
---|---|---|
200 | OK | Token deleted |
400 | Bad Request | Bad request |
404 | Not Found | Token not found |
Inlined models
DeleteAuthTokensBody
Properties
Name | Type | Required | Default | Description | Example |
---|---|---|---|---|---|
token | string | ✓ | Token name to delete |
Delete SSH key (DeleteServicesSSHKeysUsername)
DELETE /services/ssh/keys/{username}
Security Requirements
- bearerAuth
Parameters
Name | Source | Type | Required | Default | Description |
---|---|---|---|---|---|
username | path | string | ✓ | User to delete keys for | |
public_key | body | DeleteServicesSSHKeysUsernameBody | ✓ | Key to delete |
All responses
Code | Status | Description |
---|---|---|
200 | OK | SSH key deleted |
401 | Unauthorized | Unauthorized |
404 | Not Found | Key not found |
Inlined models
DeleteServicesSSHKeysUsernameBody
Properties
Name | Type | Required | Default | Description | Example |
---|---|---|---|---|---|
public_key | string | ✓ |
Delete a user (DeleteUsersUsername)
DELETE /users/{username}
Security Requirements
- bearerAuth
Parameters
Name | Source | Type | Required | Default | Description |
---|---|---|---|---|---|
username | path | string | ✓ | User to delete |
All responses
Code | Status | Description |
---|---|---|
200 | OK | Deleted user |
400 | Bad Request | Bad request |
401 | Unauthorized | Unauthorized |
404 | Not Found | User not found |
Get API version (GetAPIVersion)
GET /api/version
All responses
Code | Status | Description | Schema |
---|---|---|---|
200 | OK | API version | schema |
401 | Unauthorized | Unauthorized |
Responses
200 - API version
Status: OK
Schema
Name | Type | Required | Default | Description | Example |
---|---|---|---|---|---|
version | string | API version |
401 - Unauthorized
Status: Unauthorized
Get recovery token status (GetAuthRecoveryToken)
GET /auth/recovery_token
Security Requirements
- bearerAuth
All responses
Code | Status | Description | Has headers | Schema |
---|---|---|---|---|
200 | OK | Recovery token status | schema | |
400 | Bad Request | Bad request | schema |
Responses
200 - Recovery token status
Status: OK
Schema
Name | Type | Go type | Required | Default | Description | Example |
---|---|---|---|---|---|---|
date | string | string | Recovery token date | |||
exists | boolean | bool | Recovery token exists | |||
expiration | string | string | Recovery token expiration date | |||
uses_left | integer | int64 | Recovery token uses left | |||
valid | boolean | bool | Recovery token is valid |
400 - Bad request
Status: Bad Request
Get current device tokens (GetAuthTokens)
GET /auth/tokens
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | List of tokens |
400 | Bad Request | Bad request |
Get DKIM key from file (GetServicesMailserverDkim)
GET /services/mailserver/dkim
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | DKIM key encoded in base64 |
401 | Unauthorized | Unauthorized |
404 | Not Found | DKIM key not found |
Get all restic backups (GetServicesResticBackupList)
GET /services/restic/backup/list
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | A list of snapshots |
400 | Bad Request | Bad request |
401 | Unauthorized | Unauthorized |
Force reload snapshots (GetServicesResticBackupReload)
GET /services/restic/backup/reload
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | Snapshots reloaded |
400 | Bad Request | Bad request |
401 | Unauthorized | Unauthorized |
Get backup status (GetServicesResticBackupStatus)
GET /services/restic/backup/status
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | Backup status |
400 | Bad Request | Bad request |
401 | Unauthorized | Unauthorized |
Get current SSH settings (GetServicesSSH)
GET /services/ssh
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | SSH settings |
400 | Bad Request | Bad request |
List SSH keys (GetServicesSSHKeysUsername)
GET /services/ssh/keys/{username}
Security Requirements
- bearerAuth
Parameters
Name | Source | Type | Go type | Separator | Required | Default | Description |
---|---|---|---|---|---|---|---|
username | path | string | string | ✓ | User to list keys for |
All responses
Code | Status | Description |
---|---|---|
200 | OK | SSH keys |
401 | Unauthorized | Unauthorized |
Get service status (GetServicesStatus)
GET /services/status
All responses
Code | Status | Description | Schema |
---|---|---|---|
200 | OK | Service status | schema |
401 | Unauthorized | Unauthorized | schema |
Responses
200 - Service status
Status: OK
Schema
Name | Type | Go type | Required | Default | Description | Example |
---|---|---|---|---|---|---|
bitwarden | integer | int64 | Bitwarden service status | |||
gitea | integer | int64 | Gitea service status | |||
http | integer | int64 | Nginx service status | |||
imap | integer | int64 | Dovecot service status | |||
nextcloud | integer | int64 | Nextcloud service status | |||
ocserv | integer | int64 | OpenConnect VPN service status | |||
pleroma | integer | int64 | Pleroma service status | |||
smtp | integer | int64 | Postfix service status |
401 - Unauthorized
Status: Unauthorized
Rebuild NixOS with nixos-rebuild switch (GetSystemConfigurationApply)
GET /system/configuration/apply
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | System rebuild has started |
401 | Unauthorized | Unauthorized |
Get current system autoupgrade settings (GetSystemConfigurationAutoUpgrade)
GET /system/configuration/autoUpgrade
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | Auto-upgrade settings |
400 | Bad Request | Bad request |
Pull Repository Changes (GetSystemConfigurationPull)
GET /system/configuration/pull
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | Got update |
201 | Created | Nothing to update |
401 | Unauthorized | Unauthorized |
500 | Internal Server Error | Something went wrong |
Rollback NixOS with nixos-rebuild switch --rollback (GetSystemConfigurationRollback)
GET /system/configuration/rollback
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | System rollback has started |
401 | Unauthorized | Unauthorized |
Get current system timezone (GetSystemConfigurationTimezone)
GET /system/configuration/timezone
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | Timezone |
400 | Bad Request | Bad request |
Upgrade NixOS with nixos-rebuild switch --upgrade (GetSystemConfigurationUpgrade)
GET /system/configuration/upgrade
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | System upgrade has started |
401 | Unauthorized | Unauthorized |
Get python version used by this API (GetSystemPythonVersion)
GET /system/pythonVersion
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | OK |
401 | Unauthorized | Unauthorized |
Reboot the system (GetSystemReboot)
GET /system/reboot
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | System reboot has started |
401 | Unauthorized | Unauthorized |
Get system version from uname -a (GetSystemVersion)
GET /system/version
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | OK |
401 | Unauthorized | Unauthorized |
Get a list of users (GetUsers)
GET /users
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | A list of users |
401 | Unauthorized | Unauthorized |
Get new device token (PostAuthNewDevice)
POST /auth/new_device
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | New device token |
400 | Bad Request | Bad request |
Authorize device (PostAuthNewDeviceAuthorize)
POST /auth/new_device/authorize
Parameters
Name | Source | Type | Go type | Separator | Required | Default | Description |
---|---|---|---|---|---|---|---|
data | body | PostAuthNewDeviceAuthorizeBody | PostAuthNewDeviceAuthorizeBody | ✓ | Who is authorizing |
All responses
Code | Status | Description |
---|---|---|
200 | OK | Device authorized |
400 | Bad Request | Bad request |
404 | Not Found | Token not found |
Inlined models
PostAuthNewDeviceAuthorizeBody
Properties
Name | Type | Go type | Required | Default | Description | Example |
---|---|---|---|---|---|---|
device | string | string | Device to authorize | |||
token | string | string | Mnemonic token to authorize |
Generate recovery token (PostAuthRecoveryToken)
POST /auth/recovery_token
Security Requirements
- bearerAuth
Parameters
Name | Source | Type | Go type | Separator | Required | Default | Description |
---|---|---|---|---|---|---|---|
data | body | PostAuthRecoveryTokenBody | PostAuthRecoveryTokenBody | ✓ | Token data |
All responses
Code | Status | Description | Schema |
---|---|---|---|
200 | OK | Recovery token generated | schema |
400 | Bad Request | Bad request |
Responses
200 - Recovery token generated
Status: OK
Schema
Name | Type | Go type | Required | Default | Description | Example |
---|---|---|---|---|---|---|
token | string | string | Mnemonic recovery token |
400 - Bad request
Status: Bad Request
Inlined models
PostAuthRecoveryTokenBody
Properties
Name | Type | Go type | Required | Default | Description | Example |
---|---|---|---|---|---|---|
expiration | string | string | Token expiration date | |||
uses | integer | int64 | Token uses |
Use recovery token (PostAuthRecoveryTokenUse)
POST /auth/recovery_token/use
Parameters
Name | Source | Type | Go type | Separator | Required | Default | Description |
---|---|---|---|---|---|---|---|
data | body | PostAuthRecoveryTokenUseBody | PostAuthRecoveryTokenUseBody | ✓ | Token data |
All responses
Code | Status | Description | Schema |
---|---|---|---|
200 | OK | Recovery token used | schema |
400 | Bad Request | Bad request | |
404 | Not Found | Token not found |
Responses
200 - Recovery token used
Status: OK
Schema
Name | Type | Go type | Required | Default | Description | Example |
---|---|---|---|---|---|---|
token | string | string | Device authorization token |
Inlined models
PostAuthRecoveryTokenUseBody
Properties
Name | Type | Go type | Required | Default | Description | Example |
---|---|---|---|---|---|---|
device | string | string | Device to authorize | |||
token | string | string | Mnemonic recovery token |
Refresh token (PostAuthTokens)
POST /auth/tokens
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | Token refreshed |
400 | Bad Request | Bad request |
404 | Not Found | Token not found |
Disable Bitwarden (PostServicesBitwardenDisable)
POST /services/bitwarden/disable
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | Bitwarden disabled |
401 | Unauthorized | Unauthorized |
Enable Bitwarden (PostServicesBitwardenEnable)
POST /services/bitwarden/enable
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | Bitwarden enabled |
401 | Unauthorized | Unauthorized |
Disable Gitea (PostServicesGiteaDisable)
POST /services/gitea/disable
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | Gitea disabled |
401 | Unauthorized | Unauthorized |
Enable Gitea (PostServicesGiteaEnable)
POST /services/gitea/enable
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | Gitea enabled |
401 | Unauthorized | Unauthorized |
Disable Nextcloud (PostServicesNextcloudDisable)
POST /services/nextcloud/disable
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | Nextcloud disabled |
401 | Unauthorized | Unauthorized |
Enable Nextcloud (PostServicesNextcloudEnable)
POST /services/nextcloud/enable
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | Nextcloud enabled |
401 | Unauthorized | Unauthorized |
Disable OCserv (PostServicesOcservDisable)
POST /services/ocserv/disable
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | OCserv disabled |
401 | Unauthorized | Unauthorized |
Enable OCserv (PostServicesOcservEnable)
POST /services/ocserv/enable
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | OCserv enabled |
401 | Unauthorized | Unauthorized |
Disable Pleroma (PostServicesPleromaDisable)
POST /services/pleroma/disable
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | Pleroma disabled |
401 | Unauthorized | Unauthorized |
Enable Pleroma (PostServicesPleromaEnable)
POST /services/pleroma/enable
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | Pleroma enabled |
401 | Unauthorized | Unauthorized |
Enable SSH (PostServicesSSHEnable)
POST /services/ssh/enable
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | SSH enabled |
401 | Unauthorized | Unauthorized |
Add SSH key to the user (PostServicesSSHKeysUsername)
POST /services/ssh/keys/{username}
Security Requirements
- bearerAuth
Parameters
Name | Source | Type | Go type | Separator | Required | Default | Description |
---|---|---|---|---|---|---|---|
username | path | string | string | ✓ | User to add keys for | ||
public_key | body | PostServicesSSHKeysUsernameBody | PostServicesSSHKeysUsernameBody | ✓ |
All responses
Code | Status | Description |
---|---|---|
201 | Created | SSH key added |
401 | Unauthorized | Unauthorized |
404 | Not Found | User not found |
409 | Conflict | Key already exists |
Inlined models
PostServicesSSHKeysUsernameBody
Properties
Name | Type | Go type | Required | Default | Description | Example |
---|---|---|---|---|---|---|
public_key | string | string | ✓ |
Create a new user (PostUsers)
POST /users
Consumes
- application/json
Security Requirements
- bearerAuth
Parameters
Name | Source | Type | Go type | Separator | Required | Default | Description |
---|---|---|---|---|---|---|---|
user | body | PostUsersBody | PostUsersBody | ✓ | User to create |
All responses
Code | Status | Description |
---|---|---|
201 | Created | Created user |
400 | Bad Request | Bad request |
401 | Unauthorized | Unauthorized |
409 | Conflict | User already exists |
Inlined models
PostUsersBody
Properties
Name | Type | Go type | Required | Default | Description | Example |
---|---|---|---|---|---|---|
password | string | string | ✓ | Unix password. | ||
username | string | string | ✓ | Unix username. Must be alphanumeric and less than 32 characters |
Set the new key for backblaze (PutServicesResticBackblazeConfig)
PUT /services/restic/backblaze/config
Security Requirements
- bearerAuth
Parameters
Name | Source | Type | Go type | Separator | Required | Default | Description |
---|---|---|---|---|---|---|---|
backblazeSettings | body | PutServicesResticBackblazeConfigBody | PutServicesResticBackblazeConfigBody | ✓ | New Backblaze settings |
All responses
Code | Status | Description |
---|---|---|
200 | OK | New Backblaze settings |
400 | Bad Request | Bad request |
401 | Unauthorized | Unauthorized |
Inlined models
PutServicesResticBackblazeConfigBody
Properties
Name | Type | Go type | Required | Default | Description | Example |
---|---|---|---|---|---|---|
accountId | string | string | ✓ | |||
accountKey | string | string | ✓ | |||
bucket | string | string | ✓ |
Initiate a new restic backup (PutServicesResticBackupCreate)
PUT /services/restic/backup/create
Security Requirements
- bearerAuth
All responses
Code | Status | Description |
---|---|---|
200 | OK | Backup creation has started |
400 | Bad Request | Bad request |
401 | Unauthorized | Unauthorized |
409 | Conflict | Backup already in progress |
Start backup restoration (PutServicesResticBackupRestore)
PUT /services/restic/backup/restore
Security Requirements
- bearerAuth
Parameters
Name | Source | Type | Go type | Separator | Required | Default | Description |
---|---|---|---|---|---|---|---|
backup | body | PutServicesResticBackupRestoreBody | PutServicesResticBackupRestoreBody | ✓ | Backup to restore |
All responses
Code | Status | Description |
---|---|---|
200 | OK | Backup restoration process started |
400 | Bad Request | Bad request |
401 | Unauthorized | Unauthorized |
Inlined models
PutServicesResticBackupRestoreBody
Properties
Name | Type | Go type | Required | Default | Description | Example |
---|---|---|---|---|---|---|
backupId | string | string | ✓ |
Change SSH settings (PutServicesSSH)
PUT /services/ssh
Security Requirements
- bearerAuth
Parameters
Name | Source | Type | Go type | Separator | Required | Default | Description |
---|---|---|---|---|---|---|---|
sshSettings | body | PutServicesSSHBody | PutServicesSSHBody | ✓ | SSH settings |
All responses
Code | Status | Description |
---|---|---|
200 | OK | New settings saved |
400 | Bad Request | Bad request |
Inlined models
PutServicesSSHBody
Properties
Name | Type | Go type | Required | Default | Description | Example |
---|---|---|---|---|---|---|
enable | boolean | bool | ✓ | |||
passwordAuthentication | boolean | bool | ✓ |
Add a SSH root key (PutServicesSSHKeySend)
PUT /services/ssh/key/send
Consumes
- application/json
Security Requirements
- bearerAuth
Parameters
Name | Source | Type | Go type | Separator | Required | Default | Description |
---|---|---|---|---|---|---|---|
body | body | PutServicesSSHKeySendBody | PutServicesSSHKeySendBody | ✓ | Public key to add |
All responses
Code | Status | Description |
---|---|---|
201 | Created | Key added |
400 | Bad Request | Bad request |
401 | Unauthorized | Unauthorized |
409 | Conflict | Key already exists |
Inlined models
PutServicesSSHKeySendBody
Properties
Name | Type | Go type | Required | Default | Description | Example |
---|---|---|---|---|---|---|
public_key | string | string | ✓ | ssh-ed25519 public key. |
Change system auto upgrade settings (PutSystemConfigurationAutoUpgrade)
PUT /system/configuration/autoUpgrade
Security Requirements
- bearerAuth
Parameters
Name | Source | Type | Go type | Separator | Required | Default | Description |
---|---|---|---|---|---|---|---|
autoUpgrade | body | PutSystemConfigurationAutoUpgradeBody | PutSystemConfigurationAutoUpgradeBody | ✓ | Auto upgrade settings |
All responses
Code | Status | Description |
---|---|---|
200 | OK | New settings saved |
400 | Bad Request | Bad request |
Inlined models
PutSystemConfigurationAutoUpgradeBody
Properties
Name | Type | Go type | Required | Default | Description | Example |
---|---|---|---|---|---|---|
allowReboot | boolean | bool | ✓ | |||
enable | boolean | bool | ✓ |
Change system timezone (PutSystemConfigurationTimezone)
PUT /system/configuration/timezone
Security Requirements
- bearerAuth
Parameters
Name | Source | Type | Go type | Separator | Required | Default | Description |
---|---|---|---|---|---|---|---|
timezone | body | PutSystemConfigurationTimezoneBody | PutSystemConfigurationTimezoneBody | ✓ | Timezone to set |
All responses
Code | Status | Description |
---|---|---|
200 | OK | Timezone changed |
400 | Bad Request | Bad request |
Inlined models
PutSystemConfigurationTimezoneBody Properties
Name | Type | Go type | Required | Default | Description | Example |
---|---|---|---|---|---|---|
timezone | string | string | ✓ |
Changelog
1.2.0
- Added authorization tokens module to allow
- Having more than one device controlling the server
- Refreshing the current token
- Obtaining a recovery token
API changes
/auth/tokens
added/auth/new_device
added- Public endpoint
/auth/new_device/authorize
added. /auth/recovery_token
added- Public endpoint
/auth/recovery_token/use
added.
New migrations
- [[migrations#Create tokens JSON file|Migrate to new tokens storage]]
1.1.1
Released on 26 Jan 2022
- Added [[migrations|migration module]] which handles one-shot actions which cannot be done by nixos-configuration.
- Added [[migrations#Fix NixOS configuration branch|migration]] which changes rolling-testing branch to master, bug introduced in 0.4.0 version of the app.
1.1.0
Released on 9 Dec 2021
- Added system configuration endpoints.
- SSH management.
- Backups controller.
- Systemd is now used for system rebuilds.
WriteUserData
andReadUserData
utils added to reduce boilerplate of file locking.- Unit tests are now a thing.
API changes
/system/upgrade
is now/system/configuration/upgrade
./api/version
added./services/ssh
added./services/ssh/<username>
added./configuration/timezone
added./configuration/autoUpgrade
added./restic/backblaze/config
added./system/configuration/pull
added./services/restic/backup/reload
added.
Pre-1.1.0 changes
This is an API refactoring stage. There was no endpoint to retrieve API version, but these all were referenced as 1.1.0 version in code.
Input sanitization, added swagger
Released on 17 Nov 2021
- Addressed [[vulnerabilities#SPCVE-0001|SPCVE-0001]].
- Added Swagger documentation.
Add basic API auth
Released on 16 Nov 2021
- Added basic token auth.
Move to JSON controlled server settings
Released on 16 Nov 2021
- Assumes server already moved to JSON-controlled Nix config.
- System is now configured by usage of userdata.json.
- File locking is used now.
Decomposition
Released on 12 Nov 2021
API changes
/systemVersion
is now/system/version
./getDKIM
is now/services/mailserver/dkim
./pythonVersion
is now/system/version/pythonVersion
./users/create
is nowPOST
on/users
./users/deleteUser
is nowDELETE
on/users
./services/SERVICE_NAME/enable
and/services/SERVICE_NAME/disable
now also return message in their responses./services/ssh/key/send
: response fieldresult
renamed tostatus
.
Other changes
- Moved to Python 3.9.
- Moved to
flask_restful
'sResource
objects. distutils
is deprecated, moved tosetuptools
.
Code formatting
Black is used for code formatting.
No linting rules applied yet.
Authorization
Before 1.2.0
At that time, only one access token could be used. It is declared during nixos-infect stage and generated by the mobile app.
After 1.2.0
New auth system was introduced in 1.2.0. See [[migrations#Create tokens JSON file]] for details on migration to the new system.
Tokens storage
Tokens are stored in /etc/nixos/userdata/tokens.json
, which can be accessed only by root.
File follows this schema:
{
"$schema": "http://json-schema.org/schema#",
"$id": "https://git.selfprivacy.org/inex/selfprivacy-nixos-config/raw/branch/master/userdata/tokens_schema.json",
"type": "object",
"properties": {
"tokens": {
"type": "array",
"items": {
"type": "object",
"properties": {
"token": {
"type": "string"
},
"name": {
"type": "string"
},
"date": {
"type": "string"
}
},
"required": [
"token",
"name",
"date"
]
}
},
"recovery_token": {
"type": "object",
"properties": {
"token": {
"type": "string"
},
"date": {
"type": "string"
},
"expiration": {
"type": "string"
},
"uses_left": {
"type": "integer"
}
},
"required": [
"token",
"date"
]
},
"new_device": {
"type": "object",
"properties": {
"token": {
"type": "string"
},
"date": {
"type": "string"
},
"expiration": {
"type": "string"
}
},
"required": [
"token",
"date",
"expiration"
]
}
},
"required": [
"tokens"
]
}
i.e.:
{
"tokens": [
{
"token": "device token",
"name": "device name",
"date": "date of creation",
}
],
"recovery_token": {
"token": "recovery token",
"date": "date of creation",
"expiration": "date of expiration",
"uses_left": "number of uses left"
},
"new_device": {
"token": "new device auth token",
"date": "date of creation",
"expiration": "date of expiration",
}
}
All dates MUST follow the %Y-%m-%dT%H:%M:%S.%fZ
format.
Token control
Refer to the API documentation. You can list the tokens and delete tokens.
New device token creation
To authorize a new device, existing authorized device must acquire a new device token.
POST /auth/new_device
is used without any arguments.
New device tokens are 16 random bytes encoded to the mnemonic phrase. Token lifetime is 10 minutes or less. There can only be one token for new device auth.
This token is used by the new device to get a proper access token.
POST /auth/new_device/authorize
is used with two arguments:
token
is the new device token.- If new device token is incorrect, does not exist of expired, 404 error is returned
device
is the device name.- If the name already taken, random suffix will be added.
- Name SHOULD only contain
[^a-zA-Z0-9]
. All other symbols will be replaced with_
sequenceDiagram
actor A as Authorized device
participant Server
actor B as New device
A->>+Server: /auth/new_device
Server-->>A: Mnemonic token
Note over A,B: Mnemonic token is used by new device to get access token
B->>Server: /auth/new_device/authorize
Server-->>-B: Access token
Recovery token
Recovery tokens are 24 random bytes encoded to the mnemonic phrase. Optionally, token lifetime and allowed uses can be limited.
Only one recovery token can exist at a time. If a new token is generated, the old one is deleted.
POST /auth/recovery_token
is used to generate a recovery token. There are two optional arguments:
expiration
is the datetime when token must expire.- MUST follow the
%Y-%m-%dT%H:%M:%S.%fZ
format. - Returns 400 if time format is incorrect
- Returns 400 if date is in the past
- MUST follow the
uses
is how many times the recovery token can be used- MUST be 1 or more.
POST /auth/recovery_token/use
to use the token. Two required arguments:
token
is the recovery token- If recovery token is incorrect, does not exist of expired, 404 error is returned
device
is the device name- If the name already taken, random suffix will be added.
- Name SHOULD only contain
[^a-zA-Z0-9]
. All other symbols will be replaced with_
Migrations
Migrations module is introduced in [[changelog#1 1 1|v1.1.1]] of API and provides one-shot migrations which cannot be performed from the NixOS configuration file changes. These migrations are checked and ran before every start of the API.
You can disable certain migrations if needed by creating an array at api.skippedMigrations
in userdata.json
and populating it with IDs of the migrations to skip. Adding DISABLE_ALL
to that array disables the migrations module entirely.
For example:
...
"api": {
"token": "secret_token",
"enableSwagger": false,
"skippedMigrations": [ "fix_nixos_config_branch", "create_tokens_json" ]
},
...
Fix NixOS configuration branch
Migration ID: fix_nixos_config_branch
Introduced in: [[changelog#1 1 1|v1.1.1]]
Description
Mobile SelfPrivacy app introduced a bug in version 0.4.0. New servers were initialized with a rolling-testing nixos config branch. This was fixed in app version 0.4.2, but existing servers were not updated. This migration fixes this by changing the nixos config branch to master.
Run conditions
Git repository at /etc/nixos
is using rolling-testing
branch.
Migration process
- Moving context to
/etc/nixos
. - Running
git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
to fix the consequences of--single-branch
flag. git fetch --all
to fetch all existing branches.git pull
to pull them.git checkout master
moves to master.- Leaving the context.
Create tokens JSON file
Migration ID: create_tokens_json
Introduced in: [[changelog#1 2 0|v1.2.0]]
Description
Selfprivacy API used a single token in userdata.json
for authentication.
This migration creates a new tokens.json
file with the old token in it.
Run conditions
/etc/nixos/userdata/tokens.json
does not exist.
Migration process
- Current token is retrieved from
userdata.json
. tokens.json
is created with 0600 permission.- File is populated with the following data:
{
"tokens": [
{
"token": "token_string",
"name": "primary_token",
"date": "current date from str(datetime.now())",
}
]
}
Testing
We use pytest.
coverage run -m pytest && coverage xml && coverage report
Code formatting
Security
Linting
Pylint is recommended, but not enforced right now.
SPCVE-0001
API versions affected: [[changelog#Input sanitization added swagger https git selfprivacy org SelfPrivacy selfprivacy-rest-api pulls 5|All pre-1.1.0 releases]]
SelfPrivacy app versions affected: ≤0.2.4; fixed in 0.3.0
Discovered on: 16 Nov 2021
Addressed on: 17 Nov 2021
Description
Remote code execution vulnerability allowed root access to anyone, without any authorization. Was caused by the following factors:
- API had no authentication.
- No input sanitation used.
- Python's
subprocess.Popen
was called withshell=True
.
At that time, there was no mechanism to upgrade API, so the server had to be recreated.
Taken measures
- Basic API auth added.
- All
subprocess
calls now don't useshell=true
. - CI pipeline now includes bandit to prevent same mistakes in the future.
- More input sanitation added.
- Created a nix overlay to provide API upgrades automatically.
selfprivacy-nixos-infect
Drone configuration
Secret | Value |
---|---|
CHANNEL_SWITCHER_KEY | Bearer token for Channel Rest Api of selfprivacy.org |
CLOUDFLARE_TOKEN | Bearer token for Cloudflare to communicate with DNS entires |
DOMAIN | Full domain that points out to our testing server |
HETZNER_TOKEN | Bearer token for Hetzner to request server creation and destruction |
TEST_EMAIL_PASS | ??? |
USER_PASS | ??? |
ZONE_ID | Identificator of a zone to which all our DNS entries are related |
Cronjob Title | Branch | Cronjob Value | |
---|---|---|---|
weekly-build | development | @weekly | Our main job we run every week to ensure the upstream of our application is able to deploy onto a clean server completely. We'd like to build everyday, but for now we need to solve acme problem, since it rejects our requests if we do it every 24 hours... |
Drone pipeline
Stage Default:
Step | |
---|---|
clone | Checkout the HEAD commit |
deploy | Create infect.sh script and send it with a POST request to the clean server to deploy our testing environment |
dns | Create DNS entries for subdomains to ensure networking and certificates for properly |
sleep | Wait for the environment to build (it takes a while...) |
test | Request for overall status, do basic checks on the server |
teardown | Destroy the environment and all DNS entries, tests are over! |
switch-channel | Update upstream NixOS channel at selfprivacy.org |
It is ensured that teardown step must happen whether the pipeline fails or succeeds, because we need the server to be clean before every new job. It is done by forcing the step to be called with status trigger:
- name: teardown
. . .
when:
status:
- failure
- success
Reproted problems
NixOS fails to upgrade
We have to deploy our own channel with verified builds.
Volumes are not used properly
We need a controller which will detect them, format them, expand them and also move apps between them. Probably app should use Hetzner API to expand volume automatically.
Server control is lost when losing app's storage
Solution implemented on API side as recovery tokens in [[changelog#authorization_tokens branch|1.2.0]]. We need to implement this on app side.
Ability to change user passwords
Has to be implemented on both server and app side.
Server restoration from backup
There are several problems
We don't backup current userdata from nixos-config
So settings and users are not restored.
App don't check for the current users list
But we already have an endpoint for that.
Services are not stopped during restoration
Leads to files corruption?
User is not notified that they may have to add a credit card to b2
Free limits are pretty small and restoration may easily spend them all, and after that, everything is broken.
Disk storage is not monitored
Which leads to big problems for the server. API has to control available space, and how each app uses it. App should alert user and give options on storage management.
Backlog
No check for invalid DNSSEC setup
If DNSSEC is set up incorrectly, app won't tell user why server can't be set up.
Email can only use [a-z]
Some users wanted emails in format name.surname@domain.tld, but couldn't. As we create unix users, we have to use r"^[a-z_][a-z0-9_]+$"
. User documentation needs explanations on this?
Problems with international domains
I can't determine the scope of the problems it causes, without having one. But it surely creates a lot of problems on many stages, starting at server creation. Should we buy an international domain?
VPN
Still looking for another protocol.
HTTP headers on nextcloud are not optimal
X-Content-Type-Options is not set to "nosniff" and X-Frame-Options not set to "SAMEORIGIN".
Need more info and logs on... everything?
Especially on server creation. If we could display real-time logs of server setup, it would be perfect.
Free TLDs don't work
Reported as #84.
Servers are only deployed in Germany
Probably we should allow choosing the datacenter for the server. Also, in the future, provide more service providers.
ACME sometimes fails
We should at least start by exposing logs.
Some users want an in-depth video
I think we should make it after we handle major features of our upcoming release.
Roadmap
ToDo:
- Restore access to server
- Update control
- Disk autoresize
- SSH key add
- Fuzzing B)
- Password symbols (base64?)
- DKIM
- https://status.selfprivacy.org
- Jitsi
- OpenConnect
Desktop Release
- Linux
- Mac
- Windows
Second 100 users
- User docs
Google Playmarket, iOS AppStore
- Paid support system
- Law
- Check requrements
Backlog
- SP Infra monitoring (goss, squadcast)