feat(auth): 受信任内部调用方令牌直通(PINEAGENTS_INTERNAL_TOKEN)
- 命中内部令牌时鉴权层合成 root 身份,供 server-core 作为唯一入口无权限限制管理微服务 - 为空时关闭该能力;constant-time 比较防时序侧信道
This commit is contained in:
@@ -6,6 +6,17 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// InternalAccessToken 受信任内部调用方令牌:命中后鉴权层直接合成 root 身份,
|
||||
// 放开全部管理/root 端点(用于 server-core 作为唯一入口无权限限制地管理微服务)。
|
||||
// 为空时关闭该能力。
|
||||
//
|
||||
// 需在请求时惰性读取(而非包 init 时),因为 main() 里 godotenv.Load(".env")
|
||||
// 晚于包 init 执行,过早读取会拿到空串。
|
||||
func InternalAccessToken() string {
|
||||
return os.Getenv("PINEAGENTS_INTERNAL_TOKEN")
|
||||
}
|
||||
|
||||
|
||||
func GetEnvOrDefault(env string, defaultValue int) int {
|
||||
if env == "" || os.Getenv(env) == "" {
|
||||
return defaultValue
|
||||
|
||||
Reference in New Issue
Block a user