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 Fedora built in label #22465

Merged
merged 7 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion articles/enroll-hosts.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ Fleetd will send stdout/stderr logs to the following directories:

- macOS: `/private/var/log/orbit/orbit.std{out|err}.log`.
- Windows: `C:\Windows\system32\config\systemprofile\AppData\Local\FleetDM\Orbit\Logs\orbit-osquery.log` (the log file is rotated).
- Linux: Orbit and osqueryd stdout/stderr output is sent to syslog (`/var/log/syslog` on Debian systems and `/var/log/messages` on CentOS).
- Linux: Orbit and osqueryd stdout/stderr output is sent to syslog (`/var/log/syslog` on Debian systems, `/var/log/messages` on CentOS, and `journalctl -u orbit` on Fedora).

If the `logger_path` agent configuration is set to `filesystem`, fleetd will send osquery's "result" and "status" logs to the following directories:
- Windows: C:\Program Files\Orbit\osquery_log
Expand Down
1 change: 1 addition & 0 deletions changes/21409-fedora-label
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- added builtin label for Fedora Linux. Warning: migrations will fail if a pre-existing 'Fedora Linux' label exists. To resolve, delete the existing 'Fedora Linux' label.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package tables

import (
"database/sql"
"fmt"
"time"

"github.com/VividCortex/mysqlerr"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/go-sql-driver/mysql"
)

func init() {
MigrationClient.AddMigration(Up_20240927081858, Down_20240927081858)
}

func Up_20240927081858(tx *sql.Tx) error {
const stmt = `
INSERT INTO labels (
name,
description,
query,
platform,
label_type,
label_membership_type,
created_at,
updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
`

// hard-coded timestamps are used so that schema.sql is stable
ts := time.Date(2024, 9, 27, 0, 0, 0, 0, time.UTC)
_, err := tx.Exec(
stmt,
fleet.BuiltinLabelFedoraLinux,
"All Fedora hosts",
`select 1 from os_version where name = 'Fedora Linux';`,
"rhel",
fleet.LabelTypeBuiltIn,
fleet.LabelMembershipTypeDynamic,
ts,
ts,
)
if err != nil {
if driverErr, ok := err.(*mysql.MySQLError); ok {
if driverErr.Number == mysqlerr.ER_DUP_ENTRY {
return fmt.Errorf("a label with the name %q already exists, please rename it before applying this migration: %w", fleet.BuiltinLabelFedoraLinux, err)
}
}
return err
}
return nil
}

func Down_20240927081858(tx *sql.Tx) error {
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package tables

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestUp_20240927081858(t *testing.T) {
db := applyUpToPrev(t)

applyNext(t, db)

var names []string
err := db.Select(&names, `SELECT name FROM labels`)
require.NoError(t, err)

require.Contains(t, names, "Fedora Linux")
}
8 changes: 4 additions & 4 deletions server/datastore/mysql/schema.sql

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion server/datastore/mysql/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func targetSQLCondAndArgs(targets fleet.HostTargets) (sql string, args []interfa
OR
(
/* 'All hosts' builtin label was selected. */
id IN (SELECT DISTINCT host_id FROM label_membership WHERE label_id = 6 AND label_id IN (? /* queryLabelIDs */))
id IN (SELECT DISTINCT host_id FROM label_membership WHERE label_id = (SELECT id from labels WHERE name = 'All Hosts') AND label_id IN (? /* queryLabelIDs */))
)
OR
(
Expand Down
2 changes: 2 additions & 0 deletions server/fleet/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const (
BuiltinLabelMacOS14Plus = "macOS 14+ (Sonoma+)"
BuiltinLabelIOS = "iOS"
BuiltinLabelIPadOS = "iPadOS"
BuiltinLabelFedoraLinux = "Fedora Linux"
)

// ReservedLabelNames returns a map of label name strings
Expand All @@ -175,5 +176,6 @@ func ReservedLabelNames() map[string]struct{} {
BuiltinLabelMacOS14Plus: {},
BuiltinLabelIOS: {},
BuiltinLabelIPadOS: {},
BuiltinLabelFedoraLinux: {},
}
}
7 changes: 7 additions & 0 deletions server/test/new_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ func AddBuiltinLabels(t *testing.T, ds fleet.Datastore) {
LabelType: fleet.LabelTypeBuiltIn,
LabelMembershipType: fleet.LabelMembershipTypeManual,
},
{
Name: "Fedora Linux",
Platform: "rhel",
Query: "select 1 from os_version where name = 'Fedora Linux';",
LabelType: fleet.LabelTypeBuiltIn,
LabelMembershipType: fleet.LabelMembershipTypeDynamic,
},
}

names := fleet.ReservedLabelNames()
Expand Down
Loading