-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create pki ca import component * add serial number to cert parser * convert to ts * remove comments * reset yarn.lock * fixed yarn lock * fix comment * add declaration for base cert
- Loading branch information
1 parent
4a2fba9
commit 44e5ed5
Showing
12 changed files
with
325 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<div class="field"> | ||
<div class="form-section"> | ||
<label class="title has-padding-top is-5"> | ||
Certificate parameters | ||
</label> | ||
<form {{on "submit" (perform this.submitForm)}} data-test-pki-ca-cert-import-form> | ||
<MessageError @errorMessage={{this.errorBanner}} class="has-top-margin-s" /> | ||
<div class="box is-sideless is-fullwidth is-marginless has-top-padding-l"> | ||
<TextFile @onChange={{this.onFileUploaded}} @label="PEM Bundle" /> | ||
<p class="has-top-margin-m has-bottom-margin-l"> | ||
Issuer URLs (Issuing certificates, CRL distribution points, OCSP servers, and delta CRL URLs) can be specified by | ||
editing the individual issuer once it is uploaded to Vault. | ||
</p> | ||
</div> | ||
<div class="has-top-padding-s"> | ||
<button | ||
type="submit" | ||
class="button is-primary {{if this.submitForm.isRunning 'is-loading'}}" | ||
disabled={{this.submitForm.isRunning}} | ||
data-test-pki-ca-cert-import | ||
> | ||
Import issuer | ||
</button> | ||
<button | ||
type="button" | ||
class="button has-left-margin-s" | ||
disabled={{this.submitForm.isRunning}} | ||
{{on "click" this.cancel}} | ||
data-test-pki-ca-cert-cancel | ||
> | ||
Cancel | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { action } from '@ember/object'; | ||
import Component from '@glimmer/component'; | ||
import FlashMessageService from 'vault/services/flash-messages'; | ||
import { inject as service } from '@ember/service'; | ||
import { task } from 'ember-concurrency'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { waitFor } from '@ember/test-waiters'; | ||
import errorMessage from 'vault/utils/error-message'; | ||
import PkiBaseCertificateModel from 'vault/models/pki/certificate/base'; | ||
|
||
/** | ||
* @module PkiCaCertificateImport | ||
* PkiCaCertificateImport components are used to import PKI CA certificates and keys via pem_bundle. | ||
* https://github.com/hashicorp/vault/blob/main/website/content/api-docs/secret/pki.mdx#import-ca-certificates-and-keys | ||
* | ||
* @example | ||
* ```js | ||
* <PkiCaCertificateImport @model={{this.model}} /> | ||
* ``` | ||
* | ||
* @param {Object} model - certificate model from route | ||
* @callback onCancel - Callback triggered when cancel button is clicked. | ||
* @callback onSubmit - Callback triggered on submit success. | ||
*/ | ||
|
||
interface Args { | ||
onSave: CallableFunction; | ||
onCancel: CallableFunction; | ||
model: PkiBaseCertificateModel; | ||
} | ||
|
||
export default class PkiCaCertificateImport extends Component<Args> { | ||
@service declare readonly flashMessages: FlashMessageService; | ||
|
||
@tracked errorBanner = ''; | ||
|
||
@task | ||
@waitFor | ||
*submitForm(event: Event) { | ||
event.preventDefault(); | ||
try { | ||
yield this.args.model.save({ adapterOptions: { import: true } }); | ||
this.flashMessages.success('Successfully imported certificate.'); | ||
this.args.onSave(); | ||
} catch (error) { | ||
this.errorBanner = errorMessage(error); | ||
} | ||
} | ||
|
||
@action | ||
onFileUploaded({ value }: { value: string }) { | ||
this.args.model.pemBundle = value; | ||
} | ||
|
||
@action | ||
cancel() { | ||
this.args.model.unloadRecord(); | ||
this.args.onCancel(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,16 @@ | ||
{{! https://github.com/hashicorp/vault/blob/main/website/content/api-docs/secret/pki.mdx#import-ca-certificates-and-keys }} | ||
route: issuers.import POST /pki/issuers/import/bundle POST /pki/issuers/import/cert | ||
<PageHeader as |p|> | ||
<p.top> | ||
<Page::Breadcrumbs @breadcrumbs={{this.breadcrumbs}} /> | ||
</p.top> | ||
<p.levelLeft> | ||
<h1 class="title is-3" data-test-pki-issuer-page-title> | ||
Import a CA | ||
</h1> | ||
</p.levelLeft> | ||
</PageHeader> | ||
|
||
<PkiCaCertificateImport | ||
@model={{this.model}} | ||
@onCancel={{transition-to "vault.cluster.secrets.backend.pki.issuers.index"}} | ||
@onSave={{transition-to "vault.cluster.secrets.backend.pki.issuers.index"}} | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
ui/tests/integration/components/pki/pki-issuer-import-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render, click, fillIn } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
import { setupEngine } from 'ember-engines/test-support'; | ||
import { setupMirage } from 'ember-cli-mirage/test-support'; | ||
|
||
module('Integration | Component | pki issuer import', function (hooks) { | ||
setupRenderingTest(hooks); | ||
setupMirage(hooks); | ||
setupEngine(hooks, 'pki'); // https://github.com/ember-engines/ember-engines/pull/653 | ||
|
||
hooks.beforeEach(function () { | ||
this.store = this.owner.lookup('service:store'); | ||
this.model = this.store.createRecord('pki/issuer'); | ||
this.backend = 'pki-test'; | ||
this.secretMountPath = this.owner.lookup('service:secret-mount-path'); | ||
this.secretMountPath.currentPath = this.backend; | ||
this.pemBundle = ` | ||
-----BEGIN CERTIFICATE----- | ||
MIIDRTCCAi2gAwIBAgIUdKagCL6TnN5xLkwhPbNY8JEcY0YwDQYJKoZIhvcNAQEL | ||
BQAwGzEZMBcGA1UEAxMQd3d3LnRlc3QtaW50LmNvbTAeFw0yMzAxMDkxOTA1NTBa | ||
Fw0yMzAyMTAxOTA2MjBaMBsxGTAXBgNVBAMTEHd3dy50ZXN0LWludC5jb20wggEi | ||
MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCfd5o9JfyRAXH+E1vE2U0xjSqs | ||
A/cxDqsDXRHBnNJvzAa+7gPKXCDQZbr6chjxLXpP6Bv2/O+dZHq1fo/f6q9PDDGW | ||
JYIluwbACpe7W1UB7q9xFkZg85yQsNYokGZlwv/AMGpFBxDwVlNGL+4fxvFTv7uF | ||
mIlDzSIPrzByyCrqAFMNNqNwlAerDt/C6DMZae/rTGXIXsTfUpxPy21bzkeA+70I | ||
YCV1ffK8UnAeBYNUJ+v8+XgTQ5KhRyQ+fscUkO3T2s6f3O9Q2sWxswkf2YmZB+V1 | ||
cTZ5w6hqiuFdBXz7GRnACi1/gbWbaExQTJRplArFwIHka7dqJh8tYkXDjai3AgMB | ||
AAGjgYAwfjAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4E | ||
FgQU68/xXIgvsleKkuA8clK/6YslB/IwHwYDVR0jBBgwFoAU68/xXIgvsleKkuA8 | ||
clK/6YslB/IwGwYDVR0RBBQwEoIQd3d3LnRlc3QtaW50LmNvbTANBgkqhkiG9w0B | ||
AQsFAAOCAQEAWSff0BH3SJv/XqwN/flqc1CVzOios72/IJ+KBBv0AzFCZ8wJPi+c | ||
hH1bw7tqi01Bgh595TctogDFN1b6pjN+jrlIP4N+FF9Moj79Q+jHQMnuJomyPuI7 | ||
i07vqUcxgSmvEBBWOWS+/vxe6TfWDg18nyPf127CWQN8IHTo1f/GavX+XmRve6XT | ||
EWoqcQshEk9i87oqCbaT7B40jgjTAd1r4Cc6P4s1fAGPt9e9eqMj13kTyVDNuCoD | ||
FSZYalrlkASpg+c9oDQIh2MikGQINXHv/zIEHOW93siKMWeA4ni6phHtMg/p5eJt | ||
SxnVZsSzj8QLy2uwX1AADR0QUvJzMxptyA== | ||
-----END CERTIFICATE----- | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIEowIBAAKCAQEAn3eaPSX8kQFx/hNbxNlNMY0qrAP3MQ6rA10RwZzSb8wGvu4D | ||
ylwg0GW6+nIY8S16T+gb9vzvnWR6tX6P3+qvTwwxliWCJbsGwAqXu1tVAe6vcRZG | ||
YPOckLDWKJBmZcL/wDBqRQcQ8FZTRi/uH8bxU7+7hZiJQ80iD68wcsgq6gBTDTaj | ||
cJQHqw7fwugzGWnv60xlyF7E31KcT8ttW85HgPu9CGAldX3yvFJwHgWDVCfr/Pl4 | ||
E0OSoUckPn7HFJDt09rOn9zvUNrFsbMJH9mJmQfldXE2ecOoaorhXQV8+xkZwAot | ||
f4G1m2hMUEyUaZQKxcCB5Gu3aiYfLWJFw42otwIDAQABAoIBADC+vZ4Ne4vTtkWl | ||
Izsj9Y29Chs0xx3uzuWjUGcvib/0zOcWGICF8t3hCuu9btRiQ24jlFDGdnRVH5FV | ||
E6OtuFLgdlPgOU1RQzn2wvTZcT26+VQHLBI8xVIRTBVwNmzK06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s9S4zLBvj3+44NYOzvz2dBWP/5MuXgzFe30h9Yd0 | ||
zUlyEaWm0jY2Ylzax8ECKRL0td2bv36vxOYtTax8MSB15szsnPJ+ | ||
-----END RSA PRIVATE KEY----- | ||
`; | ||
}); | ||
|
||
test('it renders import and updates model', async function (assert) { | ||
assert.expect(3); | ||
await render( | ||
hbs` | ||
<PkiCaCertificateImport | ||
@model={{this.model}} | ||
@onCancel={{this.onCancel}} | ||
@onSave={{this.onSave}} | ||
/> | ||
`, | ||
{ owner: this.engine } | ||
); | ||
|
||
assert.dom('[data-test-pki-ca-cert-import-form]').exists('renders form'); | ||
assert.dom('[data-test-component="text-file"]').exists('renders text file input'); | ||
await click('[data-test-text-toggle]'); | ||
await fillIn('[data-test-text-file-textarea]', this.pemBundle); | ||
assert.strictEqual(this.model.pemBundle, this.pemBundle); | ||
}); | ||
|
||
test('it sends correct payload to import endpoint', async function (assert) { | ||
assert.expect(3); | ||
this.server.post(`/${this.backend}/issuers/import/bundle`, (schema, req) => { | ||
assert.ok(true, 'Request made to the correct endpoint to import issuer'); | ||
const request = JSON.parse(req.requestBody); | ||
assert.propEqual( | ||
request, | ||
{ | ||
pem_bundle: `${this.pemBundle}`, | ||
}, | ||
'sends params in correct type' | ||
); | ||
return {}; | ||
}); | ||
|
||
this.onSave = () => assert.ok(true, 'onSave callback fires on save success'); | ||
|
||
await render( | ||
hbs` | ||
<PkiCaCertificateImport | ||
@model={{this.model}} | ||
@onCancel={{this.onCancel}} | ||
@onSave={{this.onSave}} | ||
/> | ||
`, | ||
{ owner: this.engine } | ||
); | ||
|
||
await click('[data-test-text-toggle]'); | ||
await fillIn('[data-test-text-file-textarea]', this.pemBundle); | ||
assert.strictEqual(this.model.pemBundle, this.pemBundle); | ||
await click('[data-test-pki-ca-cert-import]'); | ||
}); | ||
|
||
test('it should unload record on cancel', async function (assert) { | ||
assert.expect(2); | ||
this.onCancel = () => assert.ok(true, 'onCancel callback fires'); | ||
await render( | ||
hbs` | ||
<PkiCaCertificateImport | ||
@model={{this.model}} | ||
@onCancel={{this.onCancel}} | ||
@onSave={{this.onSave}} | ||
/> | ||
`, | ||
{ owner: this.engine } | ||
); | ||
|
||
await click('[data-test-pki-ca-cert-cancel]'); | ||
assert.true(this.model.isDestroyed, 'new model is unloaded on cancel'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
To generate a declaration file run `yarn tsc <javascript file to declare> --declaration --allowJs --emitDeclarationOnly --outDir <type file location>` | ||
|
||
For example, the following command generates a declaration file called base.d.ts for the pki certificate base.js model: | ||
|
||
`yarn tsc ./app/models/pki/certificate/base.js --declaration --allowJs --emitDeclarationOnly --outDir types/vault/models/pki/certificate` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Model from '@ember-data/model'; | ||
export default class PkiCertificateBaseModel extends Model { | ||
secretMountPath: class; | ||
get useOpenAPI(): boolean; | ||
get backend(): string; | ||
getHelpUrl(): void; | ||
commonName: string; | ||
caChain: string; | ||
certificate: string; | ||
expiration: number; | ||
issuingCa: string; | ||
privateKey: string; | ||
privateKeyType: string; | ||
serialNumber: string; | ||
notValidAfter: date; | ||
notValidBefore: date; | ||
pemBundle: string; | ||
importedIssuers: string[]; | ||
importedKeys: string[]; | ||
revokePath: string; | ||
get canRevoke(): boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters