Skip to content

Commit 56a1e87

Browse files
committed
(this is a breaking change) Remove policy expansion
1 parent 507cab5 commit 56a1e87

File tree

8 files changed

+33
-634
lines changed

8 files changed

+33
-634
lines changed

libs/agent-sm/agent-policy/src/main/java/org/opensearch/secure_sm/policy/PolicyFile.java

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public class PolicyFile extends java.security.Policy {
5454
// can be updated if refresh() is called
5555
private volatile PolicyInfo policyInfo;
5656

57-
private boolean expandProperties = true;
5857
private boolean allowSystemProperties = true;
5958
private boolean notUtf8 = false;
6059
private URL url;
@@ -198,7 +197,7 @@ private boolean init(URL policy, PolicyInfo newInfo) {
198197

199198
try (InputStreamReader isr = getInputStreamReader(getInputStream(policy))) {
200199

201-
PolicyParser pp = new PolicyParser(expandProperties);
200+
PolicyParser pp = new PolicyParser();
202201
pp.read(isr);
203202

204203
Enumeration<PolicyParser.GrantEntry> enum_ = pp.grantElements();
@@ -275,9 +274,6 @@ private void addGrantEntry(PolicyParser.GrantEntry ge, PolicyInfo newInfo) {
275274
PolicyParser.PermissionEntry pe = enum_.nextElement();
276275

277276
try {
278-
// perform ${{ ... }} expansions within permission name
279-
expandPermissionName(pe);
280-
281277
Permission perm = getInstance(pe.permission, pe.name, pe.action);
282278

283279
entry.add(perm);
@@ -617,40 +613,6 @@ private static String canonPath(String path) throws IOException {
617613
}
618614
}
619615

620-
private void expandPermissionName(PolicyParser.PermissionEntry pe) throws Exception {
621-
// short cut the common case
622-
if (pe.name == null || pe.name.indexOf("${{", 0) == -1) {
623-
return;
624-
}
625-
626-
int startIndex = 0;
627-
int b, e;
628-
StringBuilder sb = new StringBuilder();
629-
while ((b = pe.name.indexOf("${{", startIndex)) != -1) {
630-
e = pe.name.indexOf("}}", b);
631-
if (e < 1) {
632-
break;
633-
}
634-
sb.append(pe.name.substring(startIndex, b));
635-
636-
// get the value in ${{...}}
637-
String value = pe.name.substring(b + 3, e);
638-
639-
// parse up to the first ':'
640-
int colonIndex;
641-
String prefix = value;
642-
String suffix;
643-
if ((colonIndex = value.indexOf(':')) != -1) {
644-
prefix = value.substring(0, colonIndex);
645-
}
646-
}
647-
648-
// copy the rest of the value
649-
sb.append(pe.name.substring(startIndex));
650-
651-
pe.name = sb.toString();
652-
}
653-
654616
/**
655617
* Each entry in the policy configuration file is represented by a
656618
* PolicyEntry object.

libs/agent-sm/agent-policy/src/main/java/org/opensearch/secure_sm/policy/PolicyParser.java

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,6 @@ public class PolicyParser {
2727

2828
private StreamTokenizer streamTokenizer;
2929
private int nextToken;
30-
private boolean expandProp = false;
31-
32-
private String expand(String value) throws PropertyExpander.ExpandException {
33-
return expand(value, false);
34-
}
35-
36-
private String expand(String value, boolean encodeURL) throws PropertyExpander.ExpandException {
37-
if (!expandProp) {
38-
return value;
39-
} else {
40-
return PropertyExpander.expand(value, encodeURL);
41-
}
42-
}
4330

4431
/**
4532
* Creates a PolicyParser object.
@@ -49,22 +36,17 @@ public PolicyParser() {
4936
grantEntries = new Vector<>();
5037
}
5138

52-
public PolicyParser(boolean expandProp) {
53-
this();
54-
this.expandProp = expandProp;
55-
}
56-
5739
/**
5840
* Reads a policy configuration into the Policy object using a
5941
* Reader object.
6042
*
6143
* @param policy the policy Reader object.
6244
*
6345
* @exception ParsingException if the policy configuration contains
64-
* a syntax error.
46+
* a syntax error.
6547
*
66-
* @exception IOException if an error occurs while reading the policy
67-
* configuration.
48+
* @exception IOException if an error occurs while reading the policy
49+
* configuration.
6850
*/
6951

7052
public void read(Reader policy) throws ParsingException, IOException {
@@ -74,17 +56,17 @@ public void read(Reader policy) throws ParsingException, IOException {
7456

7557
/*
7658
* Configure the stream tokenizer:
77-
* Recognize strings between "..."
78-
* Don't convert words to lowercase
79-
* Recognize both C-style and C++-style comments
80-
* Treat end-of-line as white space, not as a token
59+
* Recognize strings between "..."
60+
* Don't convert words to lowercase
61+
* Recognize both C-style and C++-style comments
62+
* Treat end-of-line as white space, not as a token
8163
*/
8264
streamTokenizer = Tokenizer.configureTokenizer(policy);
8365

8466
/*
85-
* The main parsing loop. The loop is executed once
86-
* for each entry in the config file. The entries
87-
* are delimited by semicolons. Once we've read in
67+
* The main parsing loop. The loop is executed once
68+
* for each entry in the config file. The entries
69+
* are delimited by semicolons. Once we've read in
8870
* the information for an entry, go ahead and try to
8971
* add it to the policy vector.
9072
*
@@ -223,34 +205,25 @@ private GrantEntry parseGrantEntry() throws ParsingException, IOException {
223205

224206
while (!peekTokenOnMatch("}")) {
225207
if (peekTokenOnMatch("Permission")) {
226-
try {
227-
PermissionEntry pe = parsePermissionEntry();
228-
e.add(pe);
229-
} catch (PropertyExpander.ExpandException peee) {
230-
skipEntry(); // BugId 4219343
231-
}
208+
209+
PermissionEntry pe = parsePermissionEntry();
210+
e.add(pe);
211+
232212
consumeTokenOnMatch(";");
233213
} else {
234214
throw new ParsingException(streamTokenizer.lineno(), "Expected permission entry");
235215
}
236216
}
237217
consumeTokenOnMatch("}");
238218

239-
try {
240-
if (e.codeBase != null) {
241-
e.codeBase = expand(e.codeBase, true).replace(File.separatorChar, '/');
242-
}
243-
} catch (PropertyExpander.ExpandException peee) {
244-
return null;
219+
if (e.codeBase != null) {
220+
e.codeBase = e.codeBase.replace(File.separatorChar, '/');
245221
}
246222

247223
return (ignoreEntry) ? null : e;
248224
}
249225

250-
/**
251-
* parse a Permission entry
252-
*/
253-
private PermissionEntry parsePermissionEntry() throws ParsingException, IOException, PropertyExpander.ExpandException {
226+
private PermissionEntry parsePermissionEntry() throws ParsingException, IOException {
254227
PermissionEntry e = new PermissionEntry();
255228

256229
// Permission
@@ -259,7 +232,7 @@ private PermissionEntry parsePermissionEntry() throws ParsingException, IOExcept
259232

260233
if (peekTokenOnMatch("\"")) {
261234
// Permission name
262-
e.name = expand(consumeTokenOnMatch("quoted string"));
235+
e.name = consumeTokenOnMatch("quoted string");
263236
}
264237

265238
if (!peekTokenOnMatch(",")) {
@@ -268,7 +241,7 @@ private PermissionEntry parsePermissionEntry() throws ParsingException, IOExcept
268241
consumeTokenOnMatch(",");
269242

270243
if (peekTokenOnMatch("\"")) {
271-
e.action = expand(consumeTokenOnMatch("quoted string"));
244+
e.action = consumeTokenOnMatch("quoted string");
272245
if (!peekTokenOnMatch(",")) {
273246
return e;
274247
}
@@ -455,12 +428,14 @@ public boolean equals(Object obj) {
455428
}
456429

457430
if (this.name == null) {
431+
458432
if (that.name != null) return false;
459433
} else {
460434
if (!this.name.equals(that.name)) return false;
461435
}
462436

463437
if (this.action == null) {
438+
464439
return that.action == null;
465440
} else {
466441
return this.action.equals(that.action);

libs/agent-sm/agent-policy/src/main/java/org/opensearch/secure_sm/policy/PropertyExpander.java

Lines changed: 0 additions & 133 deletions
This file was deleted.

0 commit comments

Comments
 (0)