
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@cag-group/utils
Advanced tools
Use in a server application to implement basic authentication in it's REST API.
The class BasicAuthChecker
is used in code the do authorization. Credentials are read from the local directory
secrets
which when running locally contains uncommitted credentials for development,
and in Kubernetes a ecret containing the credentials are mounted at secrets
so the application always reach it by:
const credentials = require('../secrets/api-credentials/api-credentials.json')
disregarding if running on a local laptop, in cloud stage or cloud prod.
Use in code like this:
const {BasicAuthChecker} = require('@cag-group/utils')
const credentials = require('../secrets/api-credentials/api-credentials.json')
...
const checker = new BasicAuthChecker(credentials)
const username = checker.getValidUser(req)
if (!username) {
console.log('Missing/invalid auth')
return res.sendStatus(401)
}
Create file api-credentials.json
in the folder secrets/api-credentials
with accounts for local tests:
[
{ "name": "u1", "pass": "somepass" },
{ "name": "u1", "pass": "changedpass" },
{ "name": "u2", "pass": "anotherpass" }
]
do not commit files in /secrets
, these are for local tests.
In the example above user "u1" is present twice with different passwords. basic-auth-checker supports this in order to support change of API-passwords without downtime.
Create a local file api-credentials.json
in the root directory with the intended users and generated passwords (see command below).
Create the secret:
kubectl -n your-namespace create secret generic api-credentials --from-file=api-credentials.json
containers:
: volumes:
- name: api-credentials
secret:
secretName: api-credentials
volumeMounts:
- name: api-credentials
mountPath: /server/secrets/api-credentials/
readOnly: true
api-credentials.json
from your secrets vault and save it in the root folder.dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 | rev | cut -b 2- | rev | tr -dc _A-Z-a-z-0-9 | head -c15;
kubectl -n your-namespace delete secret api-credentials
kubectl -n your-namespace create secret generic api-credentials --from-file=api-credentials.json
Restart the pod in order for it to read the changed secret:
kubectl -n your-namespace delete pod <podname>
FAQs
Various helpers, utilities and tools
The npm package @cag-group/utils receives a total of 5 weekly downloads. As such, @cag-group/utils popularity was classified as not popular.
We found that @cag-group/utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.