Commit c31a1a91 authored by nanahira's avatar nanahira

ci

parent 6dcc1b7c
Pipeline #5830 passed with stages
in 2 minutes and 5 seconds
node_modules/*
.DS_Store
# build files
dist
# ts
tsconfig.tsbuildinfo
# custom certificates
/ssl-*/
.git*
Dockerfile
.dockerignore
stages:
- build
- deploy
variables:
GIT_DEPTH: "1"
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
CONTAINER_TEST_ARM_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-arm
CONTAINER_TEST_X86_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-x86
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
build-x86:
stage: build
tags:
- docker
script:
- TARGET_IMAGE=$CONTAINER_TEST_IMAGE
- docker build --pull -t $TARGET_IMAGE .
- docker push $TARGET_IMAGE
deploy_latest:
stage: deploy
tags:
- docker
script:
- TARGET_IMAGE=$CONTAINER_RELEASE_IMAGE
- SOURCE_IMAGE=$CONTAINER_TEST_IMAGE
- docker pull $SOURCE_IMAGE
- docker tag $SOURCE_IMAGE $TARGET_IMAGE
- docker push $TARGET_IMAGE
only:
- master
deploy_tag:
stage: deploy
tags:
- docker
script:
- TARGET_IMAGE=$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
- SOURCE_IMAGE=$CONTAINER_TEST_IMAGE
- docker pull $SOURCE_IMAGE
- docker tag $SOURCE_IMAGE $TARGET_IMAGE
- docker push $TARGET_IMAGE
only:
- tags
FROM node:bullseye-slim
LABEL Author="Nanahira <nanahira@momobako.com>"
RUN apt update && apt -y install python3 build-essential && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /usr/src/app
COPY ./package*.json ./
RUN npm ci
COPY . ./
RUN npm run build
CMD ["npm", "run", "start"]
...@@ -5,10 +5,11 @@ const path = require('path'); ...@@ -5,10 +5,11 @@ const path = require('path');
const SSL_CERT_DIRECTORY = path.join(__dirname, './ssl/cert'); const SSL_CERT_DIRECTORY = path.join(__dirname, './ssl/cert');
module.exports = { module.exports = {
port: 1812, port: process.env.PORT || 1812,
// radius secret // radius secret
secret: 'testing123', secret: process.env.SECRET || 'testing123',
/*
certificate: { certificate: {
cert: fs.readFileSync(path.join(SSL_CERT_DIRECTORY, '/server.crt')), cert: fs.readFileSync(path.join(SSL_CERT_DIRECTORY, '/server.crt')),
key: [ key: [
...@@ -21,7 +22,9 @@ module.exports = { ...@@ -21,7 +22,9 @@ module.exports = {
// sesionIdContext: 'meiasdfkljasdft!', // sesionIdContext: 'meiasdfkljasdft!',
// ticketKeys: Buffer.from('123456789012345678901234567890123456789012345678'), // ticketKeys: Buffer.from('123456789012345678901234567890123456789012345678'),
}, },
*/
/*
// GoogleLDAPAuth (optimized for google auth) // GoogleLDAPAuth (optimized for google auth)
authentication: 'GoogleLDAPAuth', authentication: 'GoogleLDAPAuth',
authenticationOptions: { authenticationOptions: {
...@@ -32,6 +35,7 @@ module.exports = { ...@@ -32,6 +35,7 @@ module.exports = {
certFile: 'ldap.gsuite.crt', certFile: 'ldap.gsuite.crt',
}, },
}, },
*/
/** LDAP AUTH /** LDAP AUTH
authentication: 'LDAPAuth', authentication: 'LDAPAuth',
...@@ -68,10 +72,8 @@ module.exports = { ...@@ -68,10 +72,8 @@ module.exports = {
} }
*/ */
/** HTTP AUTH
authentication: 'HTTPAuth', authentication: 'HTTPAuth',
authenticationOptions: { authenticationOptions: {
url: 'https://my-website.com/api/backend-login' url: process.env.AUTH_URL || 'https://my-website.com/api/backend-login'
} }
*/
}; };
...@@ -57,20 +57,24 @@ console.log(`Auth Config: ${JSON.stringify(argv.authenticationOptions, undefined ...@@ -57,20 +57,24 @@ console.log(`Auth Config: ${JSON.stringify(argv.authenticationOptions, undefined
const radiusService = new RadiusService(config.secret, authentication); const radiusService = new RadiusService(config.secret, authentication);
server.on('message', async (msg, rinfo) => { server.on('message', async (msg, rinfo) => {
const response = await radiusService.handleMessage(msg); try {
const response = await radiusService.handleMessage(msg);
if (response) { if (response) {
server.sendToClient( server.sendToClient(
response.data, response.data,
rinfo.port, rinfo.port,
rinfo.address, rinfo.address,
(err, _bytes) => { (err, _bytes) => {
if (err) { if (err) {
console.log('Error sending response to ', rinfo); console.log('Error sending response to ', rinfo);
} }
}, },
response.expectAcknowledgment response.expectAcknowledgment
); );
}
} catch (e) {
console.error(`Error handling request: ${e.toString()}`);
} }
}); });
......
...@@ -13,25 +13,30 @@ export class HTTPAuth implements IAuthentication { ...@@ -13,25 +13,30 @@ export class HTTPAuth implements IAuthentication {
} }
async authenticate(username: string, password: string) { async authenticate(username: string, password: string) {
const result = await axios.post( try {
this.url, const result = await axios.post(
{ this.url,
username, {
password, username,
}, password,
{
validateStatus(status) {
return status >= 200 && status < 500;
}, },
{
validateStatus(status) {
return status >= 200 && status < 500;
},
}
);
if (result.status < 300) {
return true;
} }
);
console.log(`HTTP authentication failed, response code: ${result.status}`);
if (result.status === 200) {
return true; return false;
} catch (e) {
console.log(`HTTP authentication errored: ${e.toString()}`);
return false;
} }
console.log(`HTTP authentication failed, response code: ${result.status}`);
return false;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment