From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <s.ivanov@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id A3E616C548
 for <pmg-devel@lists.proxmox.com>; Mon, 29 Mar 2021 13:19:29 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 91505144AC
 for <pmg-devel@lists.proxmox.com>; Mon, 29 Mar 2021 13:18:59 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 7273C14477
 for <pmg-devel@lists.proxmox.com>; Mon, 29 Mar 2021 13:18:58 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 3F2DE448CD
 for <pmg-devel@lists.proxmox.com>; Mon, 29 Mar 2021 13:18:58 +0200 (CEST)
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pmg-devel@lists.proxmox.com
Date: Mon, 29 Mar 2021 13:18:37 +0200
Message-Id: <20210329111837.8469-1-s.ivanov@proxmox.com>
X-Mailer: git-send-email 2.20.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.060 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pmg-devel] [PATCH pmg-rs] account: create account files with 0600
 permissions
X-BeenThere: pmg-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Mail Gateway development discussion
 <pmg-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pmg-devel>, 
 <mailto:pmg-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pmg-devel/>
List-Post: <mailto:pmg-devel@lists.proxmox.com>
List-Help: <mailto:pmg-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel>, 
 <mailto:pmg-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Mon, 29 Mar 2021 11:19:29 -0000

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
quickly tested on my setup - files get created correctly

 src/acme.rs | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/acme.rs b/src/acme.rs
index ef6f4e7..4c8e5df 100644
--- a/src/acme.rs
+++ b/src/acme.rs
@@ -3,6 +3,8 @@
 //! The functions in here are perl bindings.
 
 use std::io::{self, Write};
+use std::fs::OpenOptions;
+use std::os::unix::fs::OpenOptionsExt;
 
 use anyhow::{format_err, Error};
 use serde::{Deserialize, Serialize};
@@ -85,7 +87,9 @@ impl Inner {
         };
 
         let _account = self.client.new_account(contact, tos_agreed, rsa_bits)?;
-        let file = std::fs::File::create(&account_path)
+        let mut options = OpenOptions::new();
+        options.write(true).create(true).mode(0o600);
+        let file = options.open(&account_path)
             .map_err(|err| format_err!("failed to open {:?} for writing: {}", account_path, err))?;
         self.write_to(file).map_err(|err| {
             format_err!(
@@ -137,7 +141,9 @@ impl Inner {
 
         let tmp_path = format!("{}.tmp", account_path);
         // FIXME: move proxmox::tools::replace_file & make_temp out into a nice *little* crate...
-        let mut file = std::fs::File::create(&tmp_path)
+        let mut options = OpenOptions::new();
+        options.write(true).create(true).mode(0o600);
+        let mut file = options.open(&tmp_path)
             .map_err(|err| format_err!("failed to open {:?} for writing: {}", tmp_path, err))?;
         self.write_to(&mut file).map_err(|err| {
             format_err!("failed to write acme account to {:?}: {}", tmp_path, err)
-- 
2.20.1