Merge pull request #2212 from balena-os/expose-network-service

Do not expose ports from image if service network mode
This commit is contained in:
flowzone-app[bot] 2023-10-16 02:13:38 +00:00 committed by GitHub
commit 906fee7c89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -346,7 +346,9 @@ export class Service {
'Config.ExposedPorts',
{},
);
expose = expose.concat(_.keys(imageExposedPorts));
if (!serviceNetworkMode) {
expose = expose.concat(_.keys(imageExposedPorts));
}
// Also add any exposed ports which are implied from the portMaps
const exposedFromPortMappings = _.flatMap(portMaps, (port) =>
port.toExposedPortArray(),

View File

@ -1082,6 +1082,35 @@ describe('compose/service: unit tests', () => {
return expect(dockerSvc.isEqualConfig(composeSvc, { test: 'qwerty' })).to
.be.false;
});
it('should omit exposing ports from the source image', async () => {
const s = await Service.fromComposeObject(
{
appId: '1234',
serviceName: 'foo',
releaseId: 2,
serviceId: 3,
imageId: 4,
composition: {
network_mode: 'service: test',
expose: ['433/tcp'],
},
},
{
appName: 'test',
imageInfo: {
Config: {
ExposedPorts: {
'8080/tcp': {},
},
},
},
} as any,
);
// Only explicitely exposed ports are set if network_mode: service is used
expect(s.config.expose).to.deep.equal(['433/tcp']);
});
});
describe('Security options', () => {