Skip to content

Commit 4ac70ed

Browse files
moonsnyjhjstz
authored andcommitted
Fix the wrong permissions warning on the pgpass file (#16207)
* Fix the false warning on the pgpass file The existing logic compares file modes using string comparison, which leads to false warnings on Python 3 due to the different mode representations ("0600" vs. "0o600"). To address this issue and enhance code efficiency, this PR proposes changing the comparison to an octal integer comparison. This not only eliminates false warnings but also ensures a more strict and faster comparison method, compatible with tools like "2to3".
1 parent a9f26d7 commit 4ac70ed

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

gpMgmt/bin/gppylib/db/dbconn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def __init__(self):
3838
return
3939

4040
st_info = os.stat(PGPASSFILE)
41-
mode = str(oct(st_info[stat.ST_MODE] & 0o777))
41+
mode = st_info[stat.ST_MODE] & 0o777
4242

43-
if mode != "0o600":
43+
if mode != 0o600:
4444
print('WARNING: password file "%s" has group or world access; permissions should be u=rw (0600) or less' % PGPASSFILE)
4545
self.valid_pgpass = False
4646
return

gpMgmt/test/behave/mgmt_utils/gpstart.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ Feature: gpstart behave tests
88
And a mirror has crashed
99
And the database is not running
1010
When the user runs "gpstart -a"
11+
And pgpassfile is exists
1112
Then gpstart should return a return code of 0
1213
And gpstart should print "Skipping startup of segment marked down in configuration" to stdout
1314
And gpstart should print "Skipped segment starts \(segments are marked down in configuration\) += 1" to stdout
1415
And gpstart should print "Successfully started [0-9]+ of [0-9]+ segment instances, skipped 1 other segments" to stdout
1516
And gpstart should print "Number of segments not attempted to start: 1" to stdout
17+
And gpstart should not print "permissions should be" to stdout
1618

1719
Scenario: gpstart starts even if the standby host is unreachable
1820
Given the database is running

gpMgmt/test/behave/mgmt_utils/steps/gpstart.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ def impl(context, cmd):
9191
context.stdout_message, context.stderr_message = p.communicate()
9292
context.ret_code = p.returncode
9393

94+
@when('pgpassfile is exists')
95+
def impl(context):
96+
"""
97+
Create a pgpassfile
98+
"""
99+
user_dir = os.path.expanduser("~")
100+
file_name = '.pgpass'
101+
file_path = os.path.join(user_dir, file_name)
102+
if not os.path.exists(file_path):
103+
try:
104+
with open(file_path, "w") as file:
105+
os.chmod(file_path, 0o600)
106+
except Exception as e:
107+
print("create pgpass file error")
108+
94109
@given('the host for the {seg_type} on content {content} is made unreachable')
95110
def impl(context, seg_type, content):
96111
if seg_type == "primary":

0 commit comments

Comments
 (0)