apipassword

This commit is contained in:
Karol Wypchlo 2020-07-27 17:30:05 +02:00
parent 18ae436087
commit 3b75226e0b
1 changed files with 21 additions and 15 deletions

View File

@ -135,21 +135,16 @@ server {
# proxy this call to siad endpoint (make sure the ip is correct) # proxy this call to siad endpoint (make sure the ip is correct)
proxy_pass http://siad-upload/skynet/skyfile/$dir1/$dir2/$dir3/$dir4$is_args$args; proxy_pass http://siad-upload/skynet/skyfile/$dir1/$dir2/$dir3/$dir4$is_args$args;
# rewrite_by_lua_block { rewrite_by_lua_block {
# local b64 = require("ngx.base64") local b64 = require("ngx.base64")
# -- open apipassword file for reading (b flag is required for some reason) -- put your apipassword here
# -- (file /etc/.sia/apipassword has to be mounted from the host system) local apipassword = ""
# local apipassword_file = io.open("/etc/.sia/apipassword", "rb") -- encode the user:password authorization string
# -- read apipassword file contents and trim newline (important) -- (in our case user is empty so it is just :password)
# local apipassword = apipassword_file:read("*all"):gsub("%s+", "") local content = b64.encode_base64url(":" .. apipassword)
# -- make sure to close file after reading the password -- set authorization header with proper base64 encoded string
# apipassword_file.close() ngx.req.set_header("Authorization", "Basic " .. content)
# -- encode the user:password authorization string }
# -- (in our case user is empty so it is just :password)
# local content = b64.encode_base64url(":" .. apipassword)
# -- set authorization header with proper base64 encoded string
# ngx.req.set_header("Authorization", "Basic " .. content)
# }
} }
location ~ "/skynet/skyfile/(.+)" { location ~ "/skynet/skyfile/(.+)" {
@ -169,6 +164,17 @@ server {
# proxy this call to siad endpoint (make sure the ip is correct) # proxy this call to siad endpoint (make sure the ip is correct)
proxy_pass http://siad-upload/skynet/skyfile/$siapath$is_args$args; proxy_pass http://siad-upload/skynet/skyfile/$siapath$is_args$args;
rewrite_by_lua_block {
local b64 = require("ngx.base64")
-- put your apipassword here
local apipassword = ""
-- encode the user:password authorization string
-- (in our case user is empty so it is just :password)
local content = b64.encode_base64url(":" .. apipassword)
-- set authorization header with proper base64 encoded string
ngx.req.set_header("Authorization", "Basic " .. content)
}
} }
location ~ "^/([a-zA-Z0-9-_]{46}(/.*)?)$" { location ~ "^/([a-zA-Z0-9-_]{46}(/.*)?)$" {