Skip to content

Commit b224286

Browse files
fix: check enclave key read access before mounting
1 parent 917da8b commit b224286

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

api/src/singleFunction/sconifyImage.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { join } from 'node:path';
2+
import { access, constants } from 'node:fs/promises';
23
import Docker from 'dockerode';
34
import { SCONIFY_IMAGE_NAME } from '../constants/constants.js';
45
import { logger } from '../utils/logger.js';
@@ -9,6 +10,8 @@ import { removeContainer } from './removeContainer.js';
910

1011
const docker = new Docker();
1112

13+
const ENCLAVE_KEY_PATH = join(process.cwd(), 'sig/enclave-key.pem');
14+
1215
/**
1316
* Sconifies an iapp docker image
1417
*/
@@ -44,6 +47,19 @@ export async function sconifyImage({
4447
logger.info({ sconifierImage }, 'Pulling sconifier image...');
4548
await pullSconeImage(sconifierImage);
4649

50+
if (prod) {
51+
// check signing key can be read on host
52+
try {
53+
await access(ENCLAVE_KEY_PATH, constants.R_OK);
54+
} catch (error) {
55+
logger.error(
56+
{ error, path: ENCLAVE_KEY_PATH },
57+
'Cannot read enclave key from host'
58+
);
59+
throw new Error('Cannot read enclave key from host');
60+
}
61+
}
62+
4763
const toImage = `${fromImage}-tmp-sconified-${Date.now()}`; // create an unique temporary identifier for the target image
4864
logger.info({ fromImage, toImage }, 'Sconifying...');
4965

@@ -71,9 +87,7 @@ export async function sconifyImage({
7187
: sconifyBaseCmd,
7288
HostConfig: {
7389
Binds: prod
74-
? baseBinds.concat(
75-
`${join(process.cwd(), 'sig/enclave-key.pem')}:/sig/enclave-key.pem`
76-
) // mount signing key
90+
? baseBinds.concat(`${ENCLAVE_KEY_PATH}:/sig/enclave-key.pem:ro`) // mount signing key
7791
: baseBinds,
7892
},
7993
});

0 commit comments

Comments
 (0)