🎨 Set the auth code via environment variable (#14142)

* Set auth code via env var

* Set auth code via env var (zhCN and jaJP translations)
This commit is contained in:
Germano Rizzo 2025-02-18 14:15:05 +01:00 committed by GitHub
parent 22a6c34d94
commit 0f3b94c447
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 3 deletions

View file

@ -208,6 +208,7 @@ docker run -d \
* `workspace_dir_host`: The workspace folder path on the host * `workspace_dir_host`: The workspace folder path on the host
* `workspace_dir_container`: The path of the workspace folder in the container, as specified in `--workspace` * `workspace_dir_container`: The path of the workspace folder in the container, as specified in `--workspace`
* `accessAuthCode`: Access authorization code (please **be sure to modify**, otherwise anyone can access your data) * `accessAuthCode`: Access authorization code (please **be sure to modify**, otherwise anyone can access your data)
* In alternative, it's possible to set the auth code via the `SIYUAN_ACCESS_AUTH_CODE` env variable. The commandline will always have the priority, if both are set.
To simplify things, it is recommended to configure the workspace folder path to be consistent on the host and container, such as having both `workspace_dir_host` and `workspace_dir_container` configured as `/siyuan/workspace`. The corresponding startup command would be: To simplify things, it is recommended to configure the workspace folder path to be consistent on the host and container, such as having both `workspace_dir_host` and `workspace_dir_container` configured as `/siyuan/workspace`. The corresponding startup command would be:

View file

@ -207,6 +207,7 @@ docker run -d \
* `workspace_dir_host`: ホスト上のワークスペースフォルダーのパス * `workspace_dir_host`: ホスト上のワークスペースフォルダーのパス
* `workspace_dir_container`: コンテナ内のワークスペースフォルダーのパス、`--workspace` で指定されたものと同じ * `workspace_dir_container`: コンテナ内のワークスペースフォルダーのパス、`--workspace` で指定されたものと同じ
* `accessAuthCode`: アクセス認証コード(**必ず変更してください**、そうしないと誰でもデータにアクセスできます) * `accessAuthCode`: アクセス認証コード(**必ず変更してください**、そうしないと誰でもデータにアクセスできます)
* また、`SIYUAN_ACCESS_AUTH_CODE` 環境変数を設定することで認証コードを指定することもできます。両方が設定されている場合、コマンドラインの値が優先されます。
簡略化するために、ホストとコンテナでワークスペースフォルダーのパスを一致させることをお勧めします。たとえば、`workspace_dir_host``workspace_dir_container` の両方を `/siyuan/workspace` に設定します。対応する起動コマンドは次のようになります: 簡略化するために、ホストとコンテナでワークスペースフォルダーのパスを一致させることをお勧めします。たとえば、`workspace_dir_host``workspace_dir_container` の両方を `/siyuan/workspace` に設定します。対応する起動コマンドは次のようになります:

View file

@ -212,6 +212,7 @@ docker run -d \
* `workspace_dir_host`:宿主机上的工作空间文件夹路径 * `workspace_dir_host`:宿主机上的工作空间文件夹路径
* `workspace_dir_container`:容器内工作空间文件夹路径,和后面 `--workspace` 指定成一样的 * `workspace_dir_container`:容器内工作空间文件夹路径,和后面 `--workspace` 指定成一样的
* `accessAuthCode`:访问授权码,请**务必修改**,否则任何人都可以读写你的数据 * `accessAuthCode`:访问授权码,请**务必修改**,否则任何人都可以读写你的数据
* 另外,也可以通过 `SIYUAN_ACCESS_AUTH_CODE` 环境变量设置授权码。如果两者都设置了,命令行的值将优先。
为了简化,建议将 workspace 文件夹路径在宿主机和容器上配置为一致的,比如将 `workspace_dir_host``workspace_dir_container` 都配置为 `/siyuan/workspace`,对应的启动命令示例: 为了简化,建议将 workspace 文件夹路径在宿主机和容器上配置为一致的,比如将 `workspace_dir_host``workspace_dir_container` 都配置为 `/siyuan/workspace`,对应的启动命令示例:

View file

@ -50,8 +50,9 @@ const (
) )
var ( var (
RunInContainer = false // 是否运行在容器中 RunInContainer = false // 是否运行在容器中
SiyuanAccessAuthCodeBypass = false // 是否跳过空访问授权码检查 SiyuanAccessAuthCodeBypass = false // 是否跳过空访问授权码检查
SiyuanAccessAuthCodeViaEnvvar = "" // Fallback auth code via env var (SIYUAN_ACCESS_AUTH_CODE)
) )
func initEnvVars() { func initEnvVars() {
@ -60,6 +61,7 @@ func initEnvVars() {
if SiyuanAccessAuthCodeBypass, err = strconv.ParseBool(os.Getenv("SIYUAN_ACCESS_AUTH_CODE_BYPASS")); err != nil { if SiyuanAccessAuthCodeBypass, err = strconv.ParseBool(os.Getenv("SIYUAN_ACCESS_AUTH_CODE_BYPASS")); err != nil {
SiyuanAccessAuthCodeBypass = false SiyuanAccessAuthCodeBypass = false
} }
SiyuanAccessAuthCodeViaEnvvar = os.Getenv("SIYUAN_ACCESS_AUTH_CODE")
} }
var ( var (
@ -101,6 +103,10 @@ func Boot() {
if RunInContainer { if RunInContainer {
Container = ContainerDocker Container = ContainerDocker
if "" == AccessAuthCode { if "" == AccessAuthCode {
// Priority to commandline; if not set, look into env var
AccessAuthCode = SiyuanAccessAuthCodeViaEnvvar
}
if "" == AccessAuthCode { // Still empty?
interruptBoot := true interruptBoot := true
// Set the env `SIYUAN_ACCESS_AUTH_CODE_BYPASS=true` to skip checking empty access auth code https://github.com/siyuan-note/siyuan/issues/9709 // Set the env `SIYUAN_ACCESS_AUTH_CODE_BYPASS=true` to skip checking empty access auth code https://github.com/siyuan-note/siyuan/issues/9709
@ -111,7 +117,8 @@ func Boot() {
if interruptBoot { if interruptBoot {
// The access authorization code command line parameter must be set when deploying via Docker https://github.com/siyuan-note/siyuan/issues/9328 // The access authorization code command line parameter must be set when deploying via Docker https://github.com/siyuan-note/siyuan/issues/9328
fmt.Printf("the access authorization code command line parameter (--accessAuthCode) must be set when deploying via Docker") fmt.Printf("the access authorization code command line parameter (--accessAuthCode) must be set when deploying via Docker\n")
fmt.Printf("or you can set the SIYUAN_ACCESS_AUTH_CODE env var")
os.Exit(1) os.Exit(1)
} }
} }