From 048fb3c704bd52e64b4cdc86538ef8f199f2a0e2 Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Jan 23 2024 16:00:00 +0000 Subject: import host-metering-1.2.0-4.el7_9 --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8f55e8a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +SOURCES/host-metering-1.2.0.tar.gz diff --git a/.host-metering.metadata b/.host-metering.metadata new file mode 100644 index 0000000..de947e5 --- /dev/null +++ b/.host-metering.metadata @@ -0,0 +1 @@ +548d9b79c57dbbadd45ab5a28fe28a5161b48118 SOURCES/host-metering-1.2.0.tar.gz diff --git a/SOURCES/0001-use-production-write-url.patch b/SOURCES/0001-use-production-write-url.patch new file mode 100644 index 0000000..042de87 --- /dev/null +++ b/SOURCES/0001-use-production-write-url.patch @@ -0,0 +1,42 @@ +From 8f0a491eef9fc70fe3002b197df23b0ed469bd41 Mon Sep 17 00:00:00 2001 +From: Petr Vobornik +Date: Tue, 7 Nov 2023 14:30:09 +0000 +Subject: [PATCH] use production write url + +Replace localhost with production URL. + +Signed-off-by: Petr Vobornik +--- + config/config.go | 2 +- + config/config_test.go | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/config/config.go b/config/config.go +index 8c29ec4a8fe96e8c67be7a219c113a490530845c..bda26d977acd60bf8b75490facaa3560f2aa233c 100644 +--- a/config/config.go ++++ b/config/config.go +@@ -11,7 +11,7 @@ import ( + + const ( + DefaultConfigPath = "/etc/host-metering.conf" +- DefaultWriteUrl = "http://localhost:9090/api/v1/write" ++ DefaultWriteUrl = "https://cert.console.redhat.com/api/rhel-telemetry/v1/receive" + DefaultWriteInterval = 600 * time.Second + DefaultCertPath = "/etc/pki/consumer/cert.pem" + DefaultKeyPath = "/etc/pki/consumer/key.pem" +diff --git a/config/config_test.go b/config/config_test.go +index 0ef20552b34bbb1a23ecbf0d89e2989e937334b7..b258c82d3f398c3629a7eb92bb6a34993ec8c6ca 100644 +--- a/config/config_test.go ++++ b/config/config_test.go +@@ -12,7 +12,7 @@ func TestDefaultConfig(t *testing.T) { + + // Define the expected defaults. + expectedCfg := "Config:\n" + +- "| WriteUrl: http://localhost:9090/api/v1/write\n" + ++ "| WriteUrl: https://cert.console.redhat.com/api/rhel-telemetry/v1/receive\n" + + "| WriteIntervalSec: 600\n" + + "| HostCertPath: /etc/pki/consumer/cert.pem\n" + + "| HostCertKeyPath: /etc/pki/consumer/key.pem\n" + +-- +2.41.0 + diff --git a/SOURCES/0002-feat-enable-host-metering.service-on-rpm-installatio.patch b/SOURCES/0002-feat-enable-host-metering.service-on-rpm-installatio.patch new file mode 100644 index 0000000..d496494 --- /dev/null +++ b/SOURCES/0002-feat-enable-host-metering.service-on-rpm-installatio.patch @@ -0,0 +1,83 @@ +From c3dace3c8655993572fc26f10c1e56f4cd2b8a23 Mon Sep 17 00:00:00 2001 +From: Petr Vobornik +Date: Mon, 8 Jan 2024 17:44:16 +0000 +Subject: [PATCH 1/2] feat: enable host-metering.service on rpm installation + +Use systemd preset for enabling host-metering. + +Refactor systemd calls to macros as recommended by packaging policy. + +https://issues.redhat.com/browse/HMS-3358 + +Signed-off-by: Petr Vobornik +--- + contrib/rpm/host-metering.spec.in | 22 ++++++++-------------- + contrib/systemd/80-host-metering.preset | 1 + + 2 files changed, 9 insertions(+), 14 deletions(-) + create mode 100644 contrib/systemd/80-host-metering.preset + +diff --git a/contrib/rpm/host-metering.spec.in b/contrib/rpm/host-metering.spec.in +index 892afa038aeb1caea20e22ab94cff41e6942d1c3..06de45028f9e2163756f6ffc258eeae49c7f25a6 100644 +--- a/contrib/rpm/host-metering.spec.in ++++ b/contrib/rpm/host-metering.spec.in +@@ -78,6 +78,8 @@ install -m 0755 -vd %{buildroot}%{_bindir} + install -m 0755 -vp $(pwd)/bin/* %{buildroot}%{_bindir}/ + install -m 0755 -vd %{buildroot}%{_unitdir} + install -m 644 contrib/systemd/host-metering.service %{buildroot}%{_unitdir}/%{name}.service ++install -m 0755 -vd %{buildroot}%{_presetdir} ++install -m 644 contrib/systemd/80-host-metering.preset %{buildroot}%{_presetdir}/80-%{name}.preset + install -m 0755 -vd %{buildroot}%{_mandir}/man1 + install -m 644 contrib/man/host-metering.1 %{buildroot}%{_mandir}/man1/host-metering.1 + install -m 0755 -vd %{buildroot}%{_mandir}/man5 +@@ -91,7 +93,7 @@ install -D -p -m 644 contrib/selinux/%{modulename}.if %{buildroot}%{_datadir}/se + %endif + + %post +-/bin/systemctl --system daemon-reload 2>&1 || : ++%systemd_post %{name}.service + + %post selinux + %selinux_modules_install -s %{selinuxtype} %{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp +@@ -102,20 +104,11 @@ if [ "$1" -le "1" ]; then # First install + %systemd_postun_with_restart %{modulename}.service + fi + +-%posttrans +-# restart on upgrade if was enabled +-/bin/systemctl is-enabled host-metering.service >/dev/null 2>&1 +-if [ $? -eq 0 ]; then +- /bin/systemctl restart host-metering.service >/dev/null || : +-fi +- +- + %preun +-# stop and disable on uninstallation +-if [ $1 -eq 0 ]; then +- /bin/systemctl --quiet stop host-metering.service || : +- /bin/systemctl --quiet disable host-metering.service || : +-fi ++%systemd_preun %{name}.service ++ ++%postun ++%systemd_postun_with_restart %{name}.service + + %postun selinux + if [ $1 -eq 0 ]; then +@@ -129,6 +122,7 @@ fi + %attr(644,root,root) %{_unitdir}/%{name}.service + %{_mandir}/man1/host-metering.1* + %{_mandir}/man5/host-metering.conf.5* ++%{_presetdir}/*.preset + + %files selinux + %{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp +diff --git a/contrib/systemd/80-host-metering.preset b/contrib/systemd/80-host-metering.preset +new file mode 100644 +index 0000000000000000000000000000000000000000..88677c10384bd104629a2e628e62032c99ed4f7a +--- /dev/null ++++ b/contrib/systemd/80-host-metering.preset +@@ -0,0 +1 @@ ++enable host-metering.service +-- +2.41.0 + diff --git a/SPECS/host-metering.spec b/SPECS/host-metering.spec new file mode 100644 index 0000000..414777b --- /dev/null +++ b/SPECS/host-metering.spec @@ -0,0 +1,158 @@ +%bcond_without check + +%if 0%{?rhel} <= 7 && ! 0%{?fedora} && ! 0%{?centos} +%define gobuild(o:) scl enable go-toolset-1.19 -- go build -mod vendor -buildmode pie -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${GO_LDFLAGS:-} ${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld'" -a -v %{?**}; +%endif +%if 0%{?rhel} <= 7 && ! 0%{?fedora} && 0%{?centos} + +%define gobuild(o:) go build -mod vendor -buildmode pie -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${GO_LDFLAGS:-} ${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld'" -a -v %{?**}; +%endif + +%global goipath github.com/RedHatInsights/host-metering +%global forgeurl https://github.com/RedHatInsights/host-metering/ +%global autorelease 4 +%global gomodulesmode GO111MODULE=on +%global godocs README.md +%global go_arches x86_64 s390x ppc64le + +# macros needed by SELinux +%global selinuxtype targeted +%global moduletype contrib +%global modulename host-metering + +Name: host-metering +Version: 1.2.0 +Release: %{autorelease}%{?dist} +Summary: None + +License: Apache-2.0 +URL: https://github.com/RedHatInsights/host-metering/ +ExclusiveArch: %{go_arches} + +Source: https://github.com/RedHatInsights/host-metering/releases/download/v%{version}/host-metering-%{version}.tar.gz + +# RHEL specific patches +Patch0001: 0001-use-production-write-url.patch +Patch0002: 0002-feat-enable-host-metering.service-on-rpm-installatio.patch + +%if 0%{?rhel} <= 7 && ! 0%{?fedora} && ! 0%{?centos} +BuildRequires: go-toolset-1.19 +%else +BuildRequires: golang >= 1.19 +BuildRequires: systemd-rpm-macros +%endif +BuildRequires: git +BuildRequires: policycoreutils +BuildRequires: selinux-policy +BuildRequires: selinux-policy-devel +Requires: %{name}-selinux = %{version}-%{release} + +%description +Host metering service + +%package selinux +Summary: SELinux policy module for host-metering +BuildArch: noarch +%{?selinux_requires} +Requires: %{name} = %{version}-%{release} + +%description selinux +This package installs and sets up the SELinux policy security module for host-metering. + +%prep +%setup -q -b 0 + +# for possible downstream patches +%autopatch -p1 + +%build +pwd +%gobuild -o $(pwd)/bin/host-metering %{goipath} +make build-selinux + +%pre selinux +%selinux_relabel_pre -s %{selinuxtype} + +%install +install -m 0755 -vd %{buildroot}%{_bindir} +install -m 0755 -vp $(pwd)/bin/* %{buildroot}%{_bindir}/ +install -m 0755 -vd %{buildroot}%{_unitdir} +install -m 644 contrib/systemd/host-metering.service %{buildroot}%{_unitdir}/%{name}.service +install -m 0755 -vd %{buildroot}%{_presetdir} +install -m 644 contrib/systemd/80-host-metering.preset %{buildroot}%{_presetdir}/80-%{name}.preset +install -m 0755 -vd %{buildroot}%{_mandir}/man1 +install -m 644 contrib/man/host-metering.1 %{buildroot}%{_mandir}/man1/host-metering.1 +install -m 0755 -vd %{buildroot}%{_mandir}/man5 +install -m 644 contrib/man/host-metering.conf.5 %{buildroot}%{_mandir}/man5/host-metering.conf.5 + +install -D -m 0644 contrib/selinux/%{modulename}.pp %{buildroot}%{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp +install -D -p -m 644 contrib/selinux/%{modulename}.if %{buildroot}%{_datadir}/selinux/devel/include/distributed/%{modulename}.if + +%if %{with check} +%check +%endif + +%post +%systemd_post %{name}.service + +%post selinux +%selinux_modules_install -s %{selinuxtype} %{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp +%selinux_relabel_post -s %{selinuxtype} + +if [ "$1" -le "1" ]; then # First install + # the daemon needs to be restarted for the custom label to be applied + %systemd_postun_with_restart %{modulename}.service +fi + +%preun +%systemd_preun %{name}.service + +%postun +%systemd_postun_with_restart %{name}.service + +%postun selinux +if [ $1 -eq 0 ]; then + %selinux_modules_uninstall -s %{selinuxtype} %{modulename} + %selinux_relabel_post -s %{selinuxtype} +fi + +%files +%doc README.md +%{_bindir}/* +%attr(644,root,root) %{_unitdir}/%{name}.service +%{_mandir}/man1/host-metering.1* +%{_mandir}/man5/host-metering.conf.5* +%{_presetdir}/*.preset + +%files selinux +%{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp +%{_datadir}/selinux/devel/include/distributed/%{modulename}.if +%ghost %{_sharedstatedir}/selinux/%{selinuxtype}/active/modules/200/%{modulename} + + +%changelog +* Fri Jan 12 2024 Vobornik Petr - 1.2.0-4 +- Removal of automatic start if host-metering.service on rpm installation + +* Tue Jan 9 2024 Vobornik Petr - 1.2.0-3 +- Resolves: RHEL-12368 [RFE] Add host-metering package to RHEL 7 +- Enable and start host-metering.service on rpm installation + +* Fri Jan 5 2024 Vobornik Petr - 1.2.0-2 +- Resolves: RHEL-12368 [RFE] Add host-metering package to RHEL 7 +- Fixed default writeUrl + +* Tue Dec 19 2023 Vobornik Petr - 1.2.0-1 +- Resolves: RHEL-12368 [RFE] Add host-metering package to RHEL 7 +- Rebasing to upstream release v1.2.0 + +* Wed Dec 13 2023 Vobornik Petr - 1.1.0-1 +- Resolves: RHEL-12368 [RFE] Add host-metering package to RHEL 7 +- Rebasing to upstream release v1.1.0 + +* Fri Dec 8 2023 Vobornik Petr - 1.0.0-2 +- Resolves: RHEL-12368 [RFE] Add host-metering package to RHEL 7 +- Change custom log file permission to 0600 + +* Tue Nov 7 2023 Vobornik Petr - 1.0.0-1 +- Resolves: RHEL-12368 [RFE] Add host-metering package to RHEL 7