Skip to content

Manual labels no longer factor in created_at time for exclusions - #30745

Merged
ksykulev merged 3 commits into
mainfrom
29315-exclude-any-labels
Jul 11, 2025
Merged

Manual labels no longer factor in created_at time for exclusions#30745
ksykulev merged 3 commits into
mainfrom
29315-exclude-any-labels

Conversation

@ksykulev

@ksykulev ksykulev commented Jul 10, 2025

Copy link
Copy Markdown
Contributor

Fixes #29315

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.
  • Input data is properly validated, SELECT * is avoided, SQL injection is prevented (using placeholders for values in statements)
  • Added/updated automated tests
  • Manual QA for all new/changed functionality

Summary by CodeRabbit

  • Bug Fixes

    • The "created_at" label no longer affects manual label scoping for software packages, ensuring more accurate filtering.
    • Device authentication tokens are now validated solely by their value, not by their expiration time.
  • Tests

    • Added new tests to verify label scoping logic, ensuring correct handling of dynamic and manual labels based on timestamps.

@ksykulev
ksykulev requested a review from a team as a code owner July 10, 2025 18:18
@coderabbitai

coderabbitai Bot commented Jul 10, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

The changes update label scoping logic for software installers so that manual labels are always counted regardless of timestamps, while dynamic labels still depend on the host's label update time. Related tests were added to verify this behavior. A device authentication token expiration check was also removed from host lookup logic.

Changes

File(s) Change Summary
server/datastore/mysql/software.go Updated SQL logic for label scoping: manual labels now always count, dynamic labels depend on timestamps.
server/datastore/mysql/software_test.go Added a new test to verify correct label scoping for manual and dynamic labels with respect to timestamps.
server/datastore/mysql/hosts.go Removed device authentication token expiration check from host lookup query.

Sequence Diagram(s)

sequenceDiagram
    participant Host
    participant Datastore
    participant SQL

    Host->>Datastore: Request available software installers
    Datastore->>SQL: Query with label scoping logic
    Note right of SQL: Manual labels always count<br>Dynamic labels depend on timestamps
    SQL-->>Datastore: Return filtered installers
    Datastore-->>Host: Return available installers
Loading

Assessment against linked issues

Objective Addressed Explanation
Manual labels should not consider timestamps for membership (#29315)
"Software will only be available for install on hosts that don't have any of these labels" logic is respected (#29315)
Label scoping logic for dynamic and manual labels is correctly differentiated (#29315)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Removed device authentication token expiration check (server/datastore/mysql/hosts.go) This change is unrelated to label scoping or software installer filtering as described in #29315.
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 29315-exclude-any-labels

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ksykulev

ksykulev commented Jul 10, 2025

Copy link
Copy Markdown
Contributor Author

In this case Firefox was installed by the host (not by fleet) and there is a software installer on fleet that matches.

Screenshot 2025-07-10 at 1 18 40 PM Screenshot 2025-07-10 at 1 18 30 PM

@ksykulev

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 10, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (2)
server/datastore/mysql/hosts.go (2)

601-601: Consider the security implications of removing token expiration.

By removing the expiration check, device authentication tokens will now work indefinitely regardless of their age. This could create a security vulnerability if tokens are compromised, as they would remain valid until explicitly revoked rather than expiring naturally.

Please ensure this behavioral change aligns with your security requirements and consider if additional token management mechanisms are needed.


2541-2541: Remove unused parameter from function signature.

The tokenTTL parameter is no longer used in the function implementation but remains in the signature. This creates confusion about the function's behavior and should be cleaned up.

-func (ds *Datastore) LoadHostByDeviceAuthToken(ctx context.Context, authToken string, tokenTTL time.Duration) (*fleet.Host, error) {
+func (ds *Datastore) LoadHostByDeviceAuthToken(ctx context.Context, authToken string) (*fleet.Host, error) {

Please also update all callers of this function to remove the tokenTTL argument.

🧹 Nitpick comments (1)
changes/29315-manual-label-scoping (1)

1-1: tighten the wording for clarity

a tiny grammar tweak makes the sentence smoother and consistent with the other change-log bullets in this repo.

-* Label created_at no longer factored in when scoping software packages by "exclude any" manual labels
+* The `created_at` timestamp of a label is no longer factored in when scoping software packages with the “exclude any” manual-label rule
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 729de42 and 657b34316660f1a239bb118e02c7316a5deb82b3.

📒 Files selected for processing (4)
  • changes/29315-manual-label-scoping (1 hunks)
  • server/datastore/mysql/hosts.go (1 hunks)
  • server/datastore/mysql/software.go (2 hunks)
  • server/datastore/mysql/software_test.go (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
server/datastore/mysql/hosts.go (2)

undefined

<retrieved_learning>
Learnt from: getvictor
PR: #30589
File: ee/server/service/hostidentity/depot/depot.go:104-119
Timestamp: 2025-07-08T16:06:54.576Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the security concern where shared challenges allow certificate revocation (lines 104-119) is a known issue that will be addressed in a later feature, not an immediate concern to fix.
</retrieved_learning>

<retrieved_learning>
Learnt from: getvictor
PR: #30589
File: ee/server/service/hostidentity/depot/depot.go:115-115
Timestamp: 2025-07-08T16:11:49.555Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the error from result.RowsAffected() is intentionally ignored because the information is only used for logging purposes, not for critical program logic.
</retrieved_learning>

🧬 Code Graph Analysis (1)
server/datastore/mysql/hosts.go (1)
server/fleet/hosts.go (1)
  • Host (274-388)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
  • GitHub Check: test-go (main, ubuntu-latest, mysql:8.0.36, false)
  • GitHub Check: test-go (vuln, ubuntu-latest, mysql:8.0.36, false)
  • GitHub Check: test-go (mysql, ubuntu-latest, mysql:9.3.0, false)
  • GitHub Check: test-go (vuln, ubuntu-latest, mysql:9.3.0, false)
  • GitHub Check: test-go (fleetctl, ubuntu-latest, mysql:8.0.36, false)
  • GitHub Check: test-go (main, ubuntu-latest, mysql:9.3.0, false)
  • GitHub Check: test-go (fleetctl, ubuntu-latest, mysql:9.3.0, false)
  • GitHub Check: test-go (mysql, ubuntu-latest, mysql:8.0.36, false)
  • GitHub Check: test-go (integration-mdm, ubuntu-latest, mysql:9.3.0, false)
  • GitHub Check: test-go (integration-enterprise, ubuntu-latest, mysql:8.0.36, false)
  • GitHub Check: test-go (integration-core, ubuntu-latest, mysql:9.3.0, false)
  • GitHub Check: test-go (integration-core, ubuntu-latest, mysql:8.0.36, false)
  • GitHub Check: test-go (integration-mdm, ubuntu-latest, mysql:8.0.36, false)
  • GitHub Check: test-go (integration-enterprise, ubuntu-latest, mysql:9.3.0, false)
  • GitHub Check: lint (windows-latest)
  • GitHub Check: lint (ubuntu-latest)
  • GitHub Check: lint (macos-latest)
  • GitHub Check: publish
  • GitHub Check: Analyze (go)
🔇 Additional comments (4)
server/datastore/mysql/hosts.go (1)

2541-2612: Verify this change aligns with the PR objectives.

This change removes timestamp-based filtering for device authentication tokens, which seems related to the broader PR theme about manual labels and created_at time exclusions. However, the connection isn't immediately clear from the context.

Please confirm that this device auth token change is intentionally part of this PR and not an accidental inclusion.

server/datastore/mysql/software.go (2)

670-676: Logic looks good for manual label timestamp exclusion

The conditional logic correctly implements the requirement where manual labels (label_membership_type = 1) bypass the timestamp check entirely, while dynamic labels (label_membership_type = 0) continue to respect the host_label_updated_at >= labels.created_at condition. This aligns perfectly with the PR objective.


692-698: Consistent implementation of label scoping logic

Great to see the same conditional logic pattern applied consistently in the second location within the exclude_any CTE. This ensures that manual labels are treated uniformly throughout the exclusion logic.

server/datastore/mysql/software_test.go (1)

85-85: Well-structured test for label scoping timestamp logic!

The new test case thoroughly validates the behavior where manual labels are counted regardless of timestamps while dynamic labels respect the host's label update time. This aligns perfectly with the PR objective to exclude created_at time considerations for manual labels.

Also applies to: 7970-8162

@codecov

codecov Bot commented Jul 10, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.16%. Comparing base (a51420f) to head (6a2b197).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #30745      +/-   ##
==========================================
+ Coverage   64.12%   64.16%   +0.03%     
==========================================
  Files        1879     1887       +8     
  Lines      184565   184947     +382     
  Branches     5437     5435       -2     
==========================================
+ Hits       118353   118663     +310     
- Misses      56904    56953      +49     
- Partials     9308     9331      +23     
Flag Coverage Δ
backend 65.14% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@iansltx iansltx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand the logic correctly, this is good. Just need a few more lines of tests.

Comment thread server/datastore/mysql/software_test.go

@iansltx iansltx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tweaks/explanation!

@ksykulev
ksykulev merged commit 6957f84 into main Jul 11, 2025
@ksykulev
ksykulev deleted the 29315-exclude-any-labels branch July 11, 2025 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🪲FMA/Custom packages not respecting custom scoping "exclude any" for label that doesn't exist on host

2 participants