From 0f3b94c447300383ec3a2681239242eee93190b2 Mon Sep 17 00:00:00 2001 From: Germano Rizzo <5470600+proofrock@users.noreply.github.com> Date: Tue, 18 Feb 2025 14:15:05 +0100 Subject: [PATCH] :art: Set the auth code via environment variable (#14142) * Set auth code via env var * Set auth code via env var (zhCN and jaJP translations) --- README.md | 1 + README_ja_JP.md | 1 + README_zh_CN.md | 1 + kernel/util/working.go | 13 ++++++++++--- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 799025f28..5e9f43652 100644 --- a/README.md +++ b/README.md @@ -208,6 +208,7 @@ docker run -d \ * `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` * `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: diff --git a/README_ja_JP.md b/README_ja_JP.md index 0ae3ae93d..3aa0789a3 100644 --- a/README_ja_JP.md +++ b/README_ja_JP.md @@ -207,6 +207,7 @@ docker run -d \ * `workspace_dir_host`: ホスト上のワークスペースフォルダーのパス * `workspace_dir_container`: コンテナ内のワークスペースフォルダーのパス、`--workspace` で指定されたものと同じ * `accessAuthCode`: アクセス認証コード(**必ず変更してください**、そうしないと誰でもデータにアクセスできます) + * また、`SIYUAN_ACCESS_AUTH_CODE` 環境変数を設定することで認証コードを指定することもできます。両方が設定されている場合、コマンドラインの値が優先されます。 簡略化するために、ホストとコンテナでワークスペースフォルダーのパスを一致させることをお勧めします。たとえば、`workspace_dir_host` と `workspace_dir_container` の両方を `/siyuan/workspace` に設定します。対応する起動コマンドは次のようになります: diff --git a/README_zh_CN.md b/README_zh_CN.md index 0072e5e80..6b168ef49 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -212,6 +212,7 @@ docker run -d \ * `workspace_dir_host`:宿主机上的工作空间文件夹路径 * `workspace_dir_container`:容器内工作空间文件夹路径,和后面 `--workspace` 指定成一样的 * `accessAuthCode`:访问授权码,请**务必修改**,否则任何人都可以读写你的数据 + * 另外,也可以通过 `SIYUAN_ACCESS_AUTH_CODE` 环境变量设置授权码。如果两者都设置了,命令行的值将优先。 为了简化,建议将 workspace 文件夹路径在宿主机和容器上配置为一致的,比如将 `workspace_dir_host` 和 `workspace_dir_container` 都配置为 `/siyuan/workspace`,对应的启动命令示例: diff --git a/kernel/util/working.go b/kernel/util/working.go index 89b239883..9af60b7c2 100644 --- a/kernel/util/working.go +++ b/kernel/util/working.go @@ -50,8 +50,9 @@ const ( ) var ( - RunInContainer = false // 是否运行在容器中 - SiyuanAccessAuthCodeBypass = false // 是否跳过空访问授权码检查 + RunInContainer = false // 是否运行在容器中 + SiyuanAccessAuthCodeBypass = false // 是否跳过空访问授权码检查 + SiyuanAccessAuthCodeViaEnvvar = "" // Fallback auth code via env var (SIYUAN_ACCESS_AUTH_CODE) ) func initEnvVars() { @@ -60,6 +61,7 @@ func initEnvVars() { if SiyuanAccessAuthCodeBypass, err = strconv.ParseBool(os.Getenv("SIYUAN_ACCESS_AUTH_CODE_BYPASS")); err != nil { SiyuanAccessAuthCodeBypass = false } + SiyuanAccessAuthCodeViaEnvvar = os.Getenv("SIYUAN_ACCESS_AUTH_CODE") } var ( @@ -101,6 +103,10 @@ func Boot() { if RunInContainer { Container = ContainerDocker if "" == AccessAuthCode { + // Priority to commandline; if not set, look into env var + AccessAuthCode = SiyuanAccessAuthCodeViaEnvvar + } + if "" == AccessAuthCode { // Still empty? 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 @@ -111,7 +117,8 @@ func Boot() { if interruptBoot { // 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) } }