Repository navigation
Labels
scope/k8sKubernetes commands, Helm charts, pods, services, and policiessource/agentFiled by an agenttype/bugType bug: the code does not do what it must
Description
Problem
Lines cited at 05e9388 (release/v0.2.29).
- The query sent to Loki is rewritten from a partial parse.
parse_logql_query(k8s/logql.py:152-182) reads stream selectors with_SELECTOR_REGEX(:35), which matches onlylabel="value". It drops=~,!=and!~matchers.- When
--namespaceis given and the query names no namespace,execute_logql_queryrebuildsraw_queryfrom that parse (:431-438). Line-filter patterns are re-quoted without escaping (:434). - Example:
{app=~"api.*"} |= "error" | json | level="error"with--namespace prodreaches Loki as{namespace="prod"} |= "error" | json. The matcher and the label filter are gone.
- The kubectl fallback emulates LogQL.
execute_kubectl_logql(:287-342) lists pods with only the=selectors and reads at most 5 pods (:317).- It applies the parsed filters in Python (
evaluate_log_lines,:223-254). - Everything the parser skipped is silently ignored, so a regex selector reads logs from unrelated pods.
- Durations are parsed by hand.
_parse_duration_to_seconds(:269-284) returns 3600 for anything it cannot read,1h30mincluded.- The code then computes
startandenditself (:354-362), although Loki'squery_rangetakessincedirectly. - The fallback passes the same string to
kubectl logs --since, which parses it differently.
- The request bypasses the egress factory. It uses module-level
httpx2.get(:365).
Proposed remedy
- Send the query as written. The user's query goes to Loki byte for byte, with
since,limitanddirectionas Loki parameters._parse_duration_to_secondsis deleted. --namespaceno longer rewrites the query. A query whose selector lacks the namespace fails with an error that prints the selector to use. A conflicting namespace already fails (:425-430).- The kubectl fallback does only what kubectl can.
- It accepts a selector of
label="value"matchers and|=substring filters. - It refuses anything else with an error naming
loki.url. - The emulation of LogQL pipelines (
| json,| logfmt, regex filters) is deleted.
- It accepts a selector of
- Egress. The Loki request goes through the egress factory (refactor(cli): Unify HTTP and DNS seams with shared fakes #1314).
Acceptance criteria
- The query recorded at the HTTP fake equals the input byte for byte, with and without
--namespace. -
since=1h30mreaches Loki assince=1h30m. - In fallback mode, these fail with the error naming
loki.url:{app=~"api.*"},!=matchers, label filters and| json. - In fallback mode,
{app="api"} |= "error"runskubectl logswith-l app=api(process fake). - A missing namespace fails before any request and prints the selector to use.
- Tests run offline with fakes only at process and HTTP edges; each new test runs under 1 s.
-
uv run devops cipasses.
Related: #1322, #1314, #1165 (Loki's localhost default), #691, #1357.
Found by the 2026-10-08 client-library audit.
Opened as a borrow (#1153, budget/borrowed): the agent filing quota is spent for this cycle, and this is a defect or security finding of the owner-requested 2026-10-08 client-library audit.
Metadata
Metadata
Assignees
Labels
scope/k8sKubernetes commands, Helm charts, pods, services, and policiessource/agentFiled by an agenttype/bugType bug: the code does not do what it must
Type
Projects
- StatusShow more project fieldsIn Review
Activity
dan-petty-bot commentedon Oct 8, 2026
Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.
Operators relying on 'devops k8s logs' for debugging receive silently incomplete or wrong log sets, but the tool still functions and no data is exposed or corrupted.Correct log querying is the core purpose of the command, and silent loss of matchers or filters undermines every diagnostic workflow built on it.The fix is well-scoped (pass query through unchanged, simplify fallback to kubectl-native selectors, delete hand-rolled duration parsing) but touches multiple code paths and requires new offline tests.fix(k8s): send LogQL to Loki unchanged and restrict kubectl fallback (#…
chore(main): release 0.6.0 (#2212)