Skip to content

GzipConfig silently drops gzip.Writer.Close error, GunzipConfig skips Reader.Close #8572

Description

@SebTardif

Summary

GzipConfig in pkg/operator/gzip_config.go uses defer buf.Close() on a gzip.Writer. Since Close() flushes buffered data and writes the mandatory gzip footer (CRC32 checksum + uncompressed size), discarding its error means a write failure during Close produces corrupted output that the caller cannot detect.

GunzipConfig in the same file never calls gzip.Reader.Close(). The Go standard library documentation states: "In order to verify the integrity of the data, the caller must call Close when finished reading."

Impact

Both Prometheus and Alertmanager config compression paths call GzipConfig:

  • pkg/prometheus/common.go:136 (Prometheus config secret)
  • pkg/alertmanager/operator.go:992 (Alertmanager config secret)

If Close() fails, the compressed config stored in the Kubernetes Secret is truncated (missing gzip footer). Prometheus/Alertmanager would fail to decompress the config on startup.

Suggested fix

  • GzipConfig: Return buf.Close() directly instead of deferring it.
  • GunzipConfig: Add reader.Close() after io.Copy and propagate its error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions