@riocrypto/common-server 1.0.2761 → 1.0.2764

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ declare class SecretManagerClient {
5
5
  client: SecretManagerServiceClient;
6
6
  projectId: string;
7
7
  private secretCache;
8
+ private envMismatch;
8
9
  private readonly POLL_INTERVAL_MS;
9
10
  constructor(env: RioEnv);
10
11
  /**
@@ -40,20 +40,27 @@ class SecretManagerClient {
40
40
  constructor(env) {
41
41
  this.env = env;
42
42
  this.secretCache = null;
43
+ this.envMismatch = false;
43
44
  this.POLL_INTERVAL_MS = 60 * 60 * 1000; // 1 hour
44
45
  const secretFilePath = "/etc/secrets/secret-manager/secret-manager-service-account-key.json";
45
- const secretFileContents = fs.readFileSync(secretFilePath, "utf8");
46
- const secretData = JSON.parse(secretFileContents);
47
- this.projectId = secretData.project_id;
48
- const clientEmail = secretData.client_email;
49
- const privateKey = secretData.private_key;
50
- this.client = new secret_manager_1.SecretManagerServiceClient({
51
- projectId: this.projectId,
52
- credentials: {
53
- client_email: clientEmail,
54
- private_key: privateKey,
55
- },
56
- });
46
+ if (fs.existsSync(secretFilePath)) {
47
+ const secretFileContents = fs.readFileSync(secretFilePath, "utf8");
48
+ const secretData = JSON.parse(secretFileContents);
49
+ this.projectId = secretData.project_id;
50
+ this.client = new secret_manager_1.SecretManagerServiceClient({
51
+ projectId: this.projectId,
52
+ credentials: {
53
+ client_email: secretData.client_email,
54
+ private_key: secretData.private_key,
55
+ },
56
+ });
57
+ }
58
+ else {
59
+ this.projectId = process.env.GCP_PROJECT_ID || "riocrypto";
60
+ this.client = new secret_manager_1.SecretManagerServiceClient({
61
+ projectId: this.projectId,
62
+ });
63
+ }
57
64
  }
58
65
  /**
59
66
  * Get a secret value from cache or fetch the entire secret file
@@ -61,20 +68,19 @@ class SecretManagerClient {
61
68
  */
62
69
  getSecretValue(secretId) {
63
70
  return __awaiter(this, void 0, void 0, function* () {
64
- // Check if we have a cache and the secret exists
71
+ if (this.envMismatch) {
72
+ throw new Error("Secret access blocked: RIO_ENV mismatch between service and secret file");
73
+ }
65
74
  if (this.secretCache && this.secretCache.secrets[secretId]) {
66
75
  return this.secretCache.secrets[secretId];
67
76
  }
68
- // If not in cache or cache doesn't exist, fetch entire secret file
69
77
  const success = yield this.refreshSecretCache();
70
78
  if (!success) {
71
79
  return null;
72
80
  }
73
- // Check again after refresh
74
81
  if (this.secretCache && this.secretCache.secrets[secretId]) {
75
82
  return this.secretCache.secrets[secretId];
76
83
  }
77
- // Secret not found even after refresh
78
84
  console.error(`Secret ${secretId} not found in secret file`);
79
85
  return null;
80
86
  });
@@ -116,11 +122,14 @@ class SecretManagerClient {
116
122
  throw new Error("No payload data");
117
123
  }
118
124
  const secrets = JSON.parse(version.payload.data.toString());
119
- // Clear existing polling if it exists
125
+ if (secrets.RIO_ENV && secrets.RIO_ENV !== this.env) {
126
+ console.error(`FATAL: Environment mismatch! Service expects "${this.env}" but secret file "${file}" contains RIO_ENV="${secrets.RIO_ENV}"`);
127
+ this.envMismatch = true;
128
+ return false;
129
+ }
120
130
  if ((_c = this.secretCache) === null || _c === void 0 ? void 0 : _c.pollingInterval) {
121
131
  clearInterval(this.secretCache.pollingInterval);
122
132
  }
123
- // Set up new cache with polling
124
133
  this.setupCacheWithPolling(secrets);
125
134
  console.info(`Refreshed ${Object.keys(secrets).length} secrets from ${file}`);
126
135
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.2761",
3
+ "version": "1.0.2764",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "@google-cloud/secret-manager": "^5.6.0",
25
25
  "@google-cloud/storage": "^7.19.0",
26
26
  "@hyperdx/node-opentelemetry": "^0.10.3",
27
- "@riocrypto/common": "^1.0.2558",
27
+ "@riocrypto/common": "1.0.2560",
28
28
  "@slack/web-api": "^7.15.0",
29
29
  "@types/express": "^4.17.25",
30
30
  "axios": "1.13.6",