来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
29 lines
1.2 KiB
TypeScript
29 lines
1.2 KiB
TypeScript
/** RLS fail-open 策略(供 db / tenantSchema 共用,避免循环依赖) */
|
|
|
|
function isProductionRuntime(): boolean {
|
|
return (
|
|
process.env.NODE_ENV === 'production' ||
|
|
String(process.env.APP_ENV || '').trim().toLowerCase() === 'production'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* RLS 角色缺失时是否允许降级 owner。
|
|
* 产品拍板:生产环境一律禁止应急降级(即使设置 RLS_FAIL_OPEN / ALLOW_* 也无效)。
|
|
* 非生产仍可用 RLS_FAIL_OPEN=1。
|
|
*/
|
|
export function allowRlsFailOpen(): boolean {
|
|
if (isProductionRuntime()) {
|
|
if (['1', 'true', 'yes', 'on'].includes(String(process.env.RLS_FAIL_OPEN ?? '').trim().toLowerCase())) {
|
|
console.error('[rls] 生产环境禁止 RLS_FAIL_OPEN 应急降级(产品拍板)');
|
|
}
|
|
return false;
|
|
}
|
|
const raw = String(process.env.RLS_FAIL_OPEN ?? '0').trim().toLowerCase();
|
|
return ['1', 'true', 'yes', 'on'].includes(raw);
|
|
}
|
|
|
|
export function rlsRoleMissingMessage(): string {
|
|
return 'canteen_app_rls 不可用(角色不存在,或当前数据库用户无权 SET ROLE 到它),已拒绝降级为 owner(RLS 必需)。非生产可设 RLS_FAIL_OPEN=1;生产禁止应急降级,请先修复角色/成员关系或改用超管连接';
|
|
}
|