rename to management

This commit is contained in:
Evert Prants 2022-11-12 12:14:46 +02:00
parent 26401c130a
commit 106d56f17f
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
13 changed files with 40 additions and 28 deletions

View File

@ -6,7 +6,7 @@ import { AppService } from './app.service';
import { ObjectsModule } from './modules/objects/objects.module'; import { ObjectsModule } from './modules/objects/objects.module';
import { ZoneModule } from './modules/zone/zone.module'; import { ZoneModule } from './modules/zone/zone.module';
import configuration from './config/configuration'; import configuration from './config/configuration';
import { IcynetModule } from './modules/icynet/icynet.module'; import { ManagementModule } from './modules/management/management.module';
@Module({ @Module({
imports: [ imports: [
@ -18,7 +18,7 @@ import { IcynetModule } from './modules/icynet/icynet.module';
}), }),
ObjectsModule, ObjectsModule,
ZoneModule, ZoneModule,
IcynetModule, ManagementModule,
], ],
controllers: [AppController], controllers: [AppController],
providers: [AppService], providers: [AppService],

View File

@ -11,10 +11,13 @@ export default () => ({
}, },
cacheTTL: parseInt(process.env.ZONE_CACHE_TTL, 10) || 1600, cacheTTL: parseInt(process.env.ZONE_CACHE_TTL, 10) || 1600,
zoneDir: '.', zoneDir: '.',
icynetKey: process.env.ICYNET_KEY || 'ch4ng3 m3!', managementKey: process.env.MANAGEMENT_KEY || 'ch4ng3 m3!',
rndc: { rndc: {
host: process.env.RNDC_SERVER || '127.0.0.1', host: process.env.RNDC_SERVER || '127.0.0.1',
port: parseInt(process.env.RNDC_PORT, 10) || 953, port: parseInt(process.env.RNDC_PORT, 10) || 953,
keyFile: process.env.RNDC_KEYFILE || 'rndc.key', keyFile: process.env.RNDC_KEYFILE || 'rndc.key',
}, },
managementIPs: process.env.MANAGEMENT_IP
? JSON.parse(process.env.MANAGEMENT_IP)
: ['127.0.0.1'],
}); });

View File

@ -4,19 +4,22 @@ import { Request } from 'express';
import { timingSafeEqual } from 'crypto'; import { timingSafeEqual } from 'crypto';
@Injectable() @Injectable()
export class IcynetGuard implements CanActivate { export class ManagementGuard implements CanActivate {
constructor(private config: ConfigService) {} constructor(private config: ConfigService) {}
async canActivate(context: ExecutionContext): Promise<boolean> { async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest<Request>(); const request = context.switchToHttp().getRequest<Request>();
const authHeader = request.headers.authorization;
const ips = this.config.get<string[]>('managementIPs');
if (ips.length && !ips.includes(request.ip)) return;
const authHeader = request.headers.authorization;
if (!authHeader) return false; if (!authHeader) return false;
const [base, token] = authHeader.split(' '); const [base, token] = authHeader.split(' ');
if (!base || base.toLowerCase() !== 'bearer' || !token) return false; if (!base || base.toLowerCase() !== 'bearer' || !token) return false;
const configured = this.config.get<string>('icynetKey'); const configured = this.config.get<string>('managementKey');
return timingSafeEqual(Buffer.from(token), Buffer.from(configured)); return timingSafeEqual(Buffer.from(token), Buffer.from(configured));
} }

View File

@ -1,10 +1,10 @@
import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common'; import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common';
import { Request, Response } from 'express'; import { Request, Response } from 'express';
import { ManagerService } from 'src/modules/objects/manager/manager.service'; import { DatabaseService } from 'src/modules/objects/database/database.service';
@Injectable() @Injectable()
export class ZoneAccessGuard implements CanActivate { export class ZoneAccessGuard implements CanActivate {
constructor(private service: ManagerService) {} constructor(private service: DatabaseService) {}
async canActivate(context: ExecutionContext): Promise<boolean> { async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest<Request>(); const request = context.switchToHttp().getRequest<Request>();

View File

@ -11,14 +11,14 @@ import { resolve } from 'path';
import { from, Observable, of } from 'rxjs'; import { from, Observable, of } from 'rxjs';
import { switchMap } from 'rxjs/operators'; import { switchMap } from 'rxjs/operators';
import { DNSCacheService } from 'src/modules/objects/dns/dns-cache.service'; import { DNSCacheService } from 'src/modules/objects/dns/dns-cache.service';
import { ManagerService } from 'src/modules/objects/manager/manager.service'; import { DatabaseService } from 'src/modules/objects/database/database.service';
import { CachedZone } from 'src/types/dns.interfaces'; import { CachedZone } from 'src/types/dns.interfaces';
@Injectable() @Injectable()
export class DomainInterceptor implements NestInterceptor { export class DomainInterceptor implements NestInterceptor {
constructor( constructor(
private dns: DNSCacheService, private dns: DNSCacheService,
private manage: ManagerService, private manage: DatabaseService,
private config: ConfigService, private config: ConfigService,
) {} ) {}

View File

@ -10,17 +10,17 @@ import {
UseGuards, UseGuards,
} from '@nestjs/common'; } from '@nestjs/common';
import { ApiExcludeController } from '@nestjs/swagger'; import { ApiExcludeController } from '@nestjs/swagger';
import { IcynetGuard } from 'src/guards/icynet.guard'; import { ManagementGuard } from 'src/guards/management.guard';
import { ManagerService } from '../objects/manager/manager.service'; import { DatabaseService } from '../objects/database/database.service';
import { ZoneEntity } from '../objects/manager/zone.entity'; import { ZoneEntity } from '../objects/database/zone.entity';
@ApiExcludeController() @ApiExcludeController()
@UseGuards(IcynetGuard) @UseGuards(ManagementGuard)
@Controller({ @Controller({
path: 'api/v1/icynet', path: 'api/v1/management',
}) })
export class IcynetController { export class ManagementController {
constructor(private service: ManagerService) {} constructor(private service: DatabaseService) {}
@Get('zones') @Get('zones')
async getZoneList(@Query('uuid') uuid?: string) { async getZoneList(@Query('uuid') uuid?: string) {

View File

@ -1,9 +1,9 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { ObjectsModule } from '../objects/objects.module'; import { ObjectsModule } from '../objects/objects.module';
import { IcynetController } from './icynet.controller'; import { ManagementController } from './management.controller';
@Module({ @Module({
imports: [ObjectsModule], imports: [ObjectsModule],
controllers: [IcynetController], controllers: [ManagementController],
}) })
export class IcynetModule {} export class ManagementModule {}

View File

@ -19,6 +19,12 @@ export class AccessEntity {
@ManyToOne(() => ZoneEntity, { onDelete: 'CASCADE' }) @ManyToOne(() => ZoneEntity, { onDelete: 'CASCADE' })
zone: ZoneEntity; zone: ZoneEntity;
@Column({ default: true })
allow_soa: boolean;
@Column({ default: true })
allow_zone: boolean;
@CreateDateColumn() @CreateDateColumn()
public created_at: Date; public created_at: Date;

View File

@ -2,14 +2,14 @@ import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm'; import { TypeOrmModule } from '@nestjs/typeorm';
import { AccessEntity } from './access.entity'; import { AccessEntity } from './access.entity';
import { IcynetActorEntity } from './icynet.entity'; import { IcynetActorEntity } from './icynet.entity';
import { ManagerService } from './manager.service'; import { DatabaseService } from './database.service';
import { ZoneEntity } from './zone.entity'; import { ZoneEntity } from './zone.entity';
@Module({ @Module({
imports: [ imports: [
TypeOrmModule.forFeature([AccessEntity, ZoneEntity, IcynetActorEntity]), TypeOrmModule.forFeature([AccessEntity, ZoneEntity, IcynetActorEntity]),
], ],
providers: [ManagerService], providers: [DatabaseService],
exports: [ManagerService], exports: [DatabaseService],
}) })
export class ManagerModule {} export class DatabaseModule {}

View File

@ -7,7 +7,7 @@ import { IcynetActorEntity } from './icynet.entity';
import { ZoneEntity } from './zone.entity'; import { ZoneEntity } from './zone.entity';
@Injectable() @Injectable()
export class ManagerService { export class DatabaseService {
constructor( constructor(
@InjectRepository(AccessEntity) @InjectRepository(AccessEntity)
private access: Repository<AccessEntity>, private access: Repository<AccessEntity>,

View File

@ -1,9 +1,9 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { DNSModule } from './dns/dns.module'; import { DNSModule } from './dns/dns.module';
import { ManagerModule } from './manager/manager.module'; import { DatabaseModule } from './database/database.module';
@Module({ @Module({
imports: [DNSModule, ManagerModule], imports: [DNSModule, DatabaseModule],
exports: [DNSModule, ManagerModule], exports: [DNSModule, DatabaseModule],
}) })
export class ObjectsModule {} export class ObjectsModule {}