Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add title when adding public keys #1171

Merged
merged 6 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions warpgate-admin/src/api/public_key_credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@ use super::AnySecurityScheme;
#[derive(Object)]
struct ExistingPublicKeyCredential {
id: Uuid,
openssh_public_key_title: String,
openssh_public_key: String,
}

#[derive(Object)]
struct NewPublicKeyCredential {
openssh_public_key_title: String,
openssh_public_key: String,
}

impl From<PublicKeyCredential::Model> for ExistingPublicKeyCredential {
fn from(credential: PublicKeyCredential::Model) -> Self {
Self {
id: credential.id,
openssh_public_key_title: credential.openssh_public_key_title,
openssh_public_key: credential.openssh_public_key,
}
}
Expand Down Expand Up @@ -112,6 +115,7 @@ impl ListApi {
let object = PublicKeyCredential::ActiveModel {
id: Set(Uuid::new_v4()),
user_id: Set(*user_id),
openssh_public_key_title: Set(body.openssh_public_key_title.clone()),
..PublicKeyCredential::ActiveModel::from(UserPublicKeyCredential::try_from(&*body)?)
}
.insert(&*db)
Expand Down
1 change: 1 addition & 0 deletions warpgate-db-entities/src/PublicKeyCredential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub user_id: Uuid,
pub openssh_public_key_title: String,
pub openssh_public_key: String,
}

Expand Down
2 changes: 2 additions & 0 deletions warpgate-db-migrations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod m00008_users;
mod m00009_credential_models;
mod m00010_parameters;
mod m00011_rsa_key_algos;
mod m00012_add_openssh_public_key_title;

pub struct Migrator;

Expand All @@ -31,6 +32,7 @@ impl MigratorTrait for Migrator {
Box::new(m00009_credential_models::Migration),
Box::new(m00010_parameters::Migration),
Box::new(m00011_rsa_key_algos::Migration),
Box::new(m00012_add_openssh_public_key_title::Migration),
]
}
}
Expand Down
40 changes: 40 additions & 0 deletions warpgate-db-migrations/src/m00012_add_openssh_public_key_title.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use sea_orm_migration::prelude::*;

pub struct Migration;

impl MigrationName for Migration {
fn name(&self) -> &str {
"m00012_add_openssh_public_key_title"
}
}

use crate::m00009_credential_models::public_key_credential;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(public_key_credential::Entity)
.add_column(
ColumnDef::new(Alias::new("openssh_public_key_title"))
.string()
.not_null()
).to_owned()
)
.await
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(public_key_credential::Entity)
.drop_column(Alias::new("openssh_public_key_title"))
.to_owned(),
)
.await
}

}
2 changes: 2 additions & 0 deletions warpgate-protocol-http/src/api/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ enum CredentialsStateResponse {

#[derive(Object)]
struct NewPublicKeyCredential {
openssh_public_key_title: String,
openssh_public_key: String,
}

Expand Down Expand Up @@ -288,6 +289,7 @@ impl Api {
let object = PublicKeyCredential::ActiveModel {
id: Set(Uuid::new_v4()),
user_id: Set(user_model.id),
openssh_public_key_title: Set(body.openssh_public_key_title.clone()),
openssh_public_key: Set(body.openssh_public_key.clone()),
}
.insert(&*db)
Expand Down
7 changes: 5 additions & 2 deletions warpgate-web/src/admin/CredentialEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@
editingSsoCredentialInstance = null
}

async function savePublicKeyCredential (opensshPublicKey: string) {
async function savePublicKeyCredential (opensshPublicKeyTitle: string, opensshPublicKey: string) {
// TODO: If it is an existing key, update it
// Otherwise, create a new one
if (editingPublicKeyCredentialInstance) {
editingPublicKeyCredentialInstance.opensshPublicKey = opensshPublicKey
await api.updatePublicKeyCredential({
Expand All @@ -196,6 +198,7 @@
const credential = await api.createPublicKeyCredential({
userId,
newPublicKeyCredential: {
opensshPublicKeyTitle,
opensshPublicKey,
},
})
Expand Down Expand Up @@ -250,7 +253,7 @@
{/if}
{#if credential.kind === 'PublicKey'}
<Fa fw icon={faKey} />
<span class="type">Public key</span>
<span class="type">{credential.opensshPublicKeyTitle}</span>
<span class="text-muted ms-2">{abbreviatePublicKey(credential.opensshPublicKey)}</span>
{/if}
{#if credential.kind === 'Totp'}
Expand Down
17 changes: 13 additions & 4 deletions warpgate-web/src/admin/PublicKeyCredentialModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Form,
FormGroup,
Input,
Label,
Modal,
ModalBody,
ModalFooter,
Expand All @@ -15,7 +16,7 @@
interface Props {
isOpen: boolean
instance?: ExistingPublicKeyCredential
save: (opensshPublicKey: string) => void
save: (opensshPublicKeyTitle: string, opensshPublicKey: string) => void
}

let {
Expand All @@ -25,19 +26,20 @@
}: Props = $props()

let field: HTMLInputElement|undefined = $state()
let opensshPublicKeyTitle: string = $state('')
let opensshPublicKey: string = $state('')
let validated = $state(false)

function _save () {
if (!opensshPublicKey) {
if (!opensshPublicKey || !opensshPublicKeyTitle) {
return
}
if (opensshPublicKey.includes(' ')) {
const parts = opensshPublicKey.split(' ').filter(x => x)
opensshPublicKey = `${parts[0]} ${parts[1]}`
}
isOpen = false
save(opensshPublicKey)
save(opensshPublicKeyTitle, opensshPublicKey)
}

function _cancel () {
Expand All @@ -56,9 +58,16 @@
e.preventDefault()
}}>
<ModalHeader toggle={_cancel}>
Public key
Add new SSH Public Key
</ModalHeader>
<ModalBody>
<FormGroup floating label="Title">
<Input
bind:inner={field}
type="text"
required
bind:value={opensshPublicKeyTitle} />
</FormGroup>
<FormGroup floating label="Public key in OpenSSH format">
<Input
style="font-family: monospace; height: 15rem"
Expand Down
10 changes: 9 additions & 1 deletion warpgate-web/src/admin/lib/openapi-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.0.0",
"info": {
"title": "Warpgate Web Admin",
"version": "0.11.0"
"version": "0.12.0"
},
"servers": [
{
Expand Down Expand Up @@ -2154,13 +2154,17 @@
"type": "object",
"required": [
"id",
"openssh_public_key_title",
"openssh_public_key"
],
"properties": {
"id": {
"type": "string",
"format": "uuid"
},
"openssh_public_key_title": {
"type": "string"
},
"openssh_public_key": {
"type": "string"
}
Expand Down Expand Up @@ -2272,9 +2276,13 @@
"NewPublicKeyCredential": {
"type": "object",
"required": [
"openssh_public_key_title",
"openssh_public_key"
],
"properties": {
"openssh_public_key_title": {
"type": "string"
},
"openssh_public_key": {
"type": "string"
}
Expand Down
6 changes: 5 additions & 1 deletion warpgate-web/src/gateway/lib/openapi-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.0.0",
"info": {
"title": "Warpgate HTTP proxy",
"version": "0.11.0"
"version": "0.12.0"
},
"servers": [
{
Expand Down Expand Up @@ -799,9 +799,13 @@
"NewPublicKeyCredential": {
"type": "object",
"required": [
"openssh_public_key_title",
"openssh_public_key"
],
"properties": {
"openssh_public_key_title": {
"type": "string"
},
"openssh_public_key": {
"type": "string"
}
Expand Down
Loading