Skip to content

Instantly share code, notes, and snippets.

View DeadAlready's full-sized avatar

Karl Düüna DeadAlready

View GitHub Profile
@DeadAlready
DeadAlready / fooapp.conf
Created March 28, 2016 06:43
Nginx secure configuration
# Remove server identifiers to help against enumeration
server_tokens off;
# Add some protection headers for ClickJacking
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
# Redirect to https
server {
listen 80;
@DeadAlready
DeadAlready / ip4
Created March 28, 2016 06:45
IPv4 firewall setup
*filter
# Default policy is to drop all traffic
-P INPUT DROP
-P FORWARD DROP
-P OUTPUT DROP
# Allow all loopback traffic
-A INPUT -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
@DeadAlready
DeadAlready / ip6
Created March 28, 2016 06:46
IPv6 firewall setup
*filter
# Reject all IPv6 on all chains.
-A INPUT -j DROP
-A FORWARD -j DROP
-A OUTPUT -j DROP
COMMIT
@DeadAlready
DeadAlready / app.js
Created March 28, 2016 06:49
Simple hello server
'use strict';
let http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('hello');
}).listen(2765);
@DeadAlready
DeadAlready / fooapp.service
Created March 28, 2016 06:50
Systemd configuration file
[Unit]
Description=Our cool Node.js App
After=network.target
[Service]
Type=forking
Restart=always
User=fooapp
ExecStart=/var/appdata/fooapp/node_modules/pm2/bin/pm2 start /var/appdata/fooapp/app.js
ExecStop=/var/appdata/fooapp/node_modules/pm2/bin/pm2 stop /var/appdata/fooapp/app.js
@DeadAlready
DeadAlready / easy-rbac-1.js
Last active July 9, 2019 20:32
erbac first iteration
let roles = {
manager: {
can: ['read', 'write', 'publish']
},
writer: {
can: ['read', 'write']
},
guest: {
can: ['read']
}
@DeadAlready
DeadAlready / rbac-class.js
Last active March 28, 2016 12:56
erbac in the form of a class
class RBAC {
constructor(roles) {
if(typeof roles !== 'object') {
throw new TypeError('Expected an object as input');
}
this.roles = roles;
}
can(role, operation) {
return this.roles[role] && this.roles[role].can.indexOf(operation) !== -1;
@DeadAlready
DeadAlready / role-definitions.js
Last active March 28, 2016 12:48
Role definitions
let roles = {
manager: {
can: ['publish'],
inherits: ['writer']
},
writer: {
can: ['write'],
inherits: ['guest']
},
guest: {
@DeadAlready
DeadAlready / easy-rbac-can2.js
Last active March 28, 2016 12:47
New can function
can(role, operation) {
// Check if role exists
if(!this.roles[role]) {
return false;
}
let $role = this.roles[role];
// Check if this role has access
if($role.can.indexOf(operation) !== -1) {
return true;
}
@DeadAlready
DeadAlready / role-definitions-w-function.js
Last active March 28, 2016 12:47
Functional role definitions
let roles = {
manager: {
can: ['publish'],
inherits: ['writer']
},
writer: {
can: ['write', {
name: 'edit',
when: function (params) {
return params.user.id === params.post.owner;