Skip to content

Commit

Permalink
fix: hide download audit log button if audit logs feature is disabled
Browse files Browse the repository at this point in the history
Fixes: siderolabs#616

Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
  • Loading branch information
Unix4ever committed Sep 10, 2024
1 parent b6b252e commit 4ed9049
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 252 deletions.
500 changes: 256 additions & 244 deletions client/api/omni/specs/omni.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions client/api/omni/specs/omni.proto
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,9 @@ message FeaturesConfigSpec {

// EmbeddedDiscoveryService enables the embedded discovery service.
bool embedded_discovery_service = 3;

// AuditLogEnabled is true when Omni is configured to collect the audit logs.
bool audit_log_enabled = 4;
}

message EtcdBackupSettings {
Expand Down
37 changes: 37 additions & 0 deletions client/api/omni/specs/omni_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/src/api/omni/specs/omni.pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ export type FeaturesConfigSpec = {
enable_workload_proxying?: boolean
etcd_backup_settings?: EtcdBackupSettings
embedded_discovery_service?: boolean
audit_log_enabled?: boolean
}

export type EtcdBackupSettings = {
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/methods/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export const embeddedDiscoveryServiceFeatureAvailable = async (): Promise<boolea
return featuresConfig.spec?.embedded_discovery_service ?? false;
}

export const auditLogEnabled = async (): Promise<boolean> => {
const featuresConfig = await getFeaturesConfig();

return featuresConfig.spec?.audit_log_enabled ?? false;
}

const getFeaturesConfig = async (): Promise<Resource<FeaturesConfigSpec>> => {
if (!cachedFeaturesConfig) {
cachedFeaturesConfig = await ResourceService.Get({
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/methods/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ export const downloadAuditLog = async () => {
link.download = "auditlog.jsonlog";
link.click();
} catch (e) {
showError("Failed to download audit log", e.message || e.toString());
console.log(e)
showError("Failed to download audit log", e.error?.message ?? e.message ?? e.toString());
}
};

Expand Down
20 changes: 15 additions & 5 deletions frontend/src/views/omni/Overview/Overview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,19 @@ included in the LICENSE file.
</div>
<div class="overview-card p-6 flex flex-col gap-5 place-items-stretch" style="width: 350px">
<div class="text-naturals-N14 text-sm">CLI</div>
<t-button type="primary" icon="talos-config" iconPosition="left" @click="() => downloadTalosconfig()">
<t-button type="primary" icon="document" iconPosition="left" @click="() => downloadTalosconfig()">
Download <code>talosconfig</code></t-button>
<t-button type="primary" icon="talos-config" iconPosition="left" @click="() => downloadTalosctl()">
Download talosctl</t-button>
<t-button type="primary" icon="talos-config" iconPosition="left" @click="() => downloadOmniconfig()">
<t-button type="primary" icon="document" iconPosition="left" @click="() => downloadOmniconfig()">
Download <code>omniconfig</code></t-button>
<t-button type="primary" icon="talos-config" iconPosition="left" @click="() => downloadOmnictl()">
Download omnictl</t-button>
<t-button v-if="canReadAuditLog" type="primary" icon="talos-config" iconPosition="left" @click="() => downloadAuditLog()">
Download audit log</t-button>
</div>
<div class="overview-card p-6 flex flex-col gap-5 place-items-stretch" style="width: 350px" v-if="canReadAuditLog && auditLogAvailable">
<div class="text-naturals-N14 text-sm">Tools</div>
<t-button type="primary" icon="document" iconPosition="left" @click="() => downloadAuditLog()">
Get audit logs</t-button>
</div>
</div>
</div>
Expand All @@ -148,7 +151,7 @@ import {
SysVersionID,
SysVersionType
} from "@/api/resources";
import { computed, ref } from "vue";
import { computed, onBeforeMount, ref } from "vue";
import { copyText } from "vue3-clipboard";
import { Runtime } from "@/api/common/omni.pb";

Expand All @@ -165,6 +168,7 @@ import Watch from "@/components/common/Watch/Watch.vue";
import PageHeader from "@/components/common/PageHeader.vue";
import { canCreateClusters, canReadAuditLog, canReadClusters, currentUser } from "@/methods/auth";
import { ConnectionParamsSpec } from "@/api/omni/specs/siderolink.pb";
import { auditLogEnabled } from "@/methods/features";

const hasRoleNone = computed(() => {
const role = currentUser.value?.spec?.role
Expand Down Expand Up @@ -271,6 +275,12 @@ url: "${talosLoggingKernel}"

document.body.removeChild(element);
};

const auditLogAvailable = ref(false);

onBeforeMount(async () => {
auditLogAvailable.value = await auditLogEnabled();
})
</script>

<style scoped>
Expand Down
2 changes: 1 addition & 1 deletion internal/e2e-tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (s *E2ESuite) TestAuditLog() {
s.T().Logf("getting audit log")

s.withPage(s.baseURL, func(page playwright.Page) {
downloadAuditLog := page.Locator(`span:has-text("Download audit log"):visible`)
downloadAuditLog := page.Locator(`span:has-text("Get audit log"):visible`)

s.Require().NoError(downloadAuditLog.Click())

Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func UpdateResources(ctx context.Context, st state.State, logger *zap.Logger) er
MaxInterval: durationpb.New(config.Config.EtcdBackup.MaxInterval),
}

res.TypedSpec().Value.AuditLogEnabled = config.Config.AuditLogDir != ""

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/version/data/tag
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.42.0-beta.0
v0.42.0-beta.0

0 comments on commit 4ed9049

Please sign in to comment.