minor improvements

This commit is contained in:
pablof7z 2023-06-28 21:44:39 +02:00
parent f949c116db
commit db0c9ae3fb
6 changed files with 40 additions and 25 deletions

View File

@ -1,15 +1,19 @@
FROM --platform=linux/amd64 node:19 as build FROM --platform=linux/amd64 node:19-buster-slim as build
WORKDIR /app WORKDIR /app
COPY package.json package-lock.json . COPY package.json package-lock.json .
RUN npm i RUN npm i
COPY src/ src/ COPY src/ src/
COPY prisma/ prisma/ COPY prisma/schema.prisma prisma/
COPY tsconfig.json . COPY tsconfig.json .
RUN apt-get update -y && apt-get install -y openssl
RUN npm run build RUN npm run build
RUN npx prisma generate
RUN npx prisma migrate deploy RUN npx prisma migrate deploy
ENTRYPOINT [ "node", "dist/index.js" ] ENTRYPOINT [ "node", "dist/index.js" ]
CMD ["start"] CMD ["start"]

View File

@ -5,8 +5,21 @@ Daemon to remotely sign nostr events using keys.
To quickly install `nsecbunkerd` via Docker just run: To quickly install `nsecbunkerd` via Docker just run:
### Prepare your config directory
``` ```
docker run -d --name nsecbunkerd pablof7z/nsecbunkerd start --admin <your-npub> mkdir $HOME/.nsecbunker-config
```
### Start nsecbunkerd
```
docker run -d --name nsecbunkerd -v $HOME/.nsecbunker-config:/app/config pablof7z/nsecbunkerd start --admin <your-npub>
docker exec -i nsecbunkerd npx prisma db push
```
### Get the connection string
```
docker exec nsecbunkerd cat /app/connection.txt
``` ```
nsecBunker will give you a connection string like: nsecBunker will give you a connection string like:
@ -15,7 +28,8 @@ nsecBunker will give you a connection string like:
bunker://npub1tj2dmc4udvgafxxxxxxxrtgne8j8l6rgrnaykzc8sys9mzfcz@relay.nsecbunker.com bunker://npub1tj2dmc4udvgafxxxxxxxrtgne8j8l6rgrnaykzc8sys9mzfcz@relay.nsecbunker.com
``` ```
You can visit https://app.nsecbunker.com/ to administrate your nsecBunker remotely. You can visit https://app.nsecbunker.com/ to administrate your nsecBunker remotely, or explore `nsecbunkerd`'s CLI
to find the options to add and approve keys from the CLI.
## Hard setup: ## Hard setup:
(If you installed via docker you don't need to do any of this, skip to the [Configure](#configure) section) (If you installed via docker you don't need to do any of this, skip to the [Configure](#configure) section)

View File

@ -1,6 +1,6 @@
{ {
"name": "nsecbunkerd", "name": "nsecbunkerd",
"version": "0.6.2", "version": "0.6.4",
"description": "nsecbunker daemon", "description": "nsecbunker daemon",
"main": "dist/index.js", "main": "dist/index.js",
"bin": { "bin": {
@ -16,7 +16,7 @@
], ],
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/sanity-island/nsecbunker" "url": "https://github.com/kind-0/nsecbunkerd"
}, },
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",

View File

@ -1,40 +1,36 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client { generator client {
provider = "prisma-client-js" provider = "prisma-client-js"
} }
datasource db { datasource db {
provider = "sqlite" provider = "sqlite"
url = "file:./nsecbunker.db" url = "file:../config/nsecbunker.db"
} }
model KeyUser { model KeyUser {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
keyName String keyName String
userPubkey String userPubkey String
description String?
signingConditions SigningCondition[]
logs Log[]
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt updatedAt DateTime @default(now()) @updatedAt
lastUsedAt DateTime? lastUsedAt DateTime?
description String?
logs Log[]
signingConditions SigningCondition[]
Token Token[] Token Token[]
@@unique([keyName, userPubkey], name: "unique_key_user") @@unique([keyName, userPubkey], name: "unique_key_user")
} }
model SigningCondition { model SigningCondition {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
method String? method String?
kind String? kind String?
content String? content String?
keyUserKeyName String? keyUserKeyName String?
allowed Boolean? allowed Boolean?
KeyUser KeyUser? @relation(fields: [keyUserId], references: [id])
keyUserId Int? keyUserId Int?
KeyUser KeyUser? @relation(fields: [keyUserId], references: [id])
} }
model Log { model Log {
@ -43,18 +39,18 @@ model Log {
type String type String
method String? method String?
params String? params String?
KeyUser KeyUser? @relation(fields: [keyUserId], references: [id])
keyUserId Int? keyUserId Int?
KeyUser KeyUser? @relation(fields: [keyUserId], references: [id])
} }
model Policy { model Policy {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
name String name String
description String?
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt updatedAt DateTime @default(now()) @updatedAt
deletedAt DateTime?
expiresAt DateTime? expiresAt DateTime?
deletedAt DateTime?
description String?
rules PolicyRule[] rules PolicyRule[]
Token Token[] Token Token[]
} }
@ -65,9 +61,8 @@ model PolicyRule {
kind String? kind String?
maxUsageCount Int? maxUsageCount Int?
currentUsageCount Int? currentUsageCount Int?
policyId Int?
Policy Policy? @relation(fields: [policyId], references: [id]) Policy Policy? @relation(fields: [policyId], references: [id])
policyId Int?
} }
model Token { model Token {
@ -81,8 +76,8 @@ model Token {
deletedAt DateTime? deletedAt DateTime?
expiresAt DateTime? expiresAt DateTime?
redeemedAt DateTime? redeemedAt DateTime?
KeyUser KeyUser? @relation(fields: [keyUserId], references: [id])
keyUserId Int? keyUserId Int?
policy Policy? @relation(fields: [policyId], references: [id])
policyId Int? policyId Int?
policy Policy? @relation(fields: [policyId], references: [id])
KeyUser KeyUser? @relation(fields: [keyUserId], references: [id])
} }

View File

@ -38,6 +38,8 @@ function getKeys(config: DaemonConfig) {
const key = { const key = {
name, name,
npub: user.npub, npub: user.npub,
userCount: await prisma.keyUser.count({ where: { keyName: name } }),
tokenCount: await prisma.token.count({ where: { keyName: name } })
}; };
lockedKeyNames = lockedKeyNames.filter((keyName) => keyName !== name); lockedKeyNames = lockedKeyNames.filter((keyName) => keyName !== name);

View File

@ -68,7 +68,7 @@ const argv = yargs(hideBin(process.argv))
alias: 'c', alias: 'c',
type: 'string', type: 'string',
description: 'Path to config file', description: 'Path to config file',
default: 'nsecbunker.json', default: 'config/nsecbunker.json',
}, },
}) })
.demandCommand(0, 1) .demandCommand(0, 1)