-
Notifications
You must be signed in to change notification settings - Fork 864
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PermissioningService Besu Plugin (#2218)
* Permissioning: Add plugin extension point Added plugin extension point to allow developers to write their own implementation of `NodePermissioningProvider::isPermitted` This will allow developers to implement their own interpretations of things like on-chain permissioning. Signed-off-by: Antony Denyer <git@antonydenyer.co.uk> * refactor: rename NodePermissioningProvider::isPermitted Interface will be used for other pemissioning needs Signed-off-by: Antony Denyer <git@antonydenyer.co.uk> * Permissioning: added hook for NodeMessagePermissioning All message sent to a peer will call into isMessagePermitted if providers have been registered through the plugin api Signed-off-by: Antony Denyer <git@antonydenyer.co.uk> * AcceptanceTests: test node nodePermissioningProvider 4 node cluster with permissioning blocking a direct between two nodes and permissioning blocking transaction messages for a single node Signed-off-by: Antony Denyer <git@antonydenyer.co.uk> * fix: unit tests for NodePermissioningControllerFactory Signed-off-by: Antony Denyer <git@antonydenyer.co.uk> * fix: fat finger typo Signed-off-by: Antony Denyer <git@antonydenyer.co.uk> * fix: reduce likely hood of flakey test Signed-off-by: Antony Denyer <git@antonydenyer.co.uk> * fix: remove comment Signed-off-by: Antony Denyer <git@antonydenyer.co.uk> * fix: typos Signed-off-by: Antony Denyer <git@antonydenyer.co.uk> * fix: remove jitpack references Signed-off-by: Antony Denyer <git@antonydenyer.co.uk> * fix: tidy up EthPeerTest args Signed-off-by: Antony Denyer <git@antonydenyer.co.uk> * fix: update plugin hash check Signed-off-by: Antony Denyer <git@antonydenyer.co.uk> * fix: improve test reliability Signed-off-by: Antony Denyer <git@antonydenyer.co.uk> * refactor: move test-plugins out from besu/main into acceptance-tests Signed-off-by: Antony Denyer <git@antonydenyer.co.uk>
- Loading branch information
1 parent
a3e12f3
commit 840d364
Showing
63 changed files
with
825 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,4 @@ site/ | |
/kubernetes/reports/ | ||
/kubernetes/besu-*.tar.gz | ||
**/src/*/generated | ||
jitpack.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...rc/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/admin/ExpectHasPeer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.hyperledger.besu.tests.acceptance.dsl.condition.admin; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; | ||
import org.hyperledger.besu.tests.acceptance.dsl.node.Node; | ||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.admin.AdminPeersTransaction; | ||
|
||
import java.util.List; | ||
|
||
public class ExpectHasPeer implements Condition { | ||
|
||
private final String peer; | ||
private final AdminPeersTransaction transaction; | ||
|
||
public ExpectHasPeer(final String peer, final AdminPeersTransaction transaction) { | ||
this.peer = peer; | ||
this.transaction = transaction; | ||
} | ||
|
||
@Override | ||
public void verify(final Node node) { | ||
final List<String> result = node.execute(transaction); | ||
assertThat(result).contains(peer); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...ain/java/org/hyperledger/besu/tests/acceptance/dsl/condition/admin/ExpectNotHavePeer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.hyperledger.besu.tests.acceptance.dsl.condition.admin; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; | ||
import org.hyperledger.besu.tests.acceptance.dsl.node.Node; | ||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.admin.AdminPeersTransaction; | ||
|
||
import java.util.List; | ||
|
||
public class ExpectNotHavePeer implements Condition { | ||
|
||
private final String peer; | ||
private final AdminPeersTransaction transaction; | ||
|
||
public ExpectNotHavePeer(final String peer, final AdminPeersTransaction transaction) { | ||
this.peer = peer; | ||
this.transaction = transaction; | ||
} | ||
|
||
@Override | ||
public void verify(final Node node) { | ||
final List<String> result = node.execute(transaction); | ||
assertThat(result).doesNotContain(peer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...va/org/hyperledger/besu/tests/acceptance/dsl/transaction/admin/AdminPeersTransaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.hyperledger.besu.tests.acceptance.dsl.transaction.admin; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; | ||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.web3j.protocol.core.methods.response.admin.AdminPeers; | ||
|
||
public class AdminPeersTransaction implements Transaction<List<String>> { | ||
|
||
public AdminPeersTransaction() {} | ||
|
||
@Override | ||
public List<String> execute(final NodeRequests node) { | ||
try { | ||
final AdminPeers resp = node.eth().adminPeers().send(); | ||
assertThat(resp).isNotNull(); | ||
assertThat(resp.hasError()).isFalse(); | ||
return resp.getResult().stream().map(AdminPeers.Peer::getId).collect(Collectors.toList()); | ||
} catch (final IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
dependencies { | ||
implementation project(':plugin-api') | ||
implementation project(':besu') | ||
implementation 'com.google.auto.service:auto-service' | ||
implementation 'info.picocli:picocli' | ||
implementation 'org.apache.logging.log4j:log4j-api' | ||
implementation 'org.apache.logging.log4j:log4j-core' | ||
|
||
testImplementation 'org.assertj:assertj-core' | ||
testImplementation 'junit:junit' | ||
} | ||
|
||
task testPluginsJar(type: Jar) { | ||
archiveFileName = 'testPlugins.jar' | ||
manifest { | ||
attributes( | ||
'Specification-Title': archiveBaseName, | ||
'Specification-Version': project.version, | ||
'Implementation-Title': archiveBaseName, | ||
'Implementation-Version': calculateVersion() | ||
) | ||
} | ||
from sourceSets.main.output | ||
} | ||
|
||
artifacts { testPluginsJar } | ||
|
||
|
||
javadoc { | ||
enabled = false | ||
} |
File renamed without changes.
File renamed without changes.
81 changes: 81 additions & 0 deletions
81
...ests/test-plugins/src/main/java/org/hyperledger/besu/plugins/TestPermissioningPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.hyperledger.besu.plugins; | ||
|
||
import org.hyperledger.besu.plugin.BesuContext; | ||
import org.hyperledger.besu.plugin.BesuPlugin; | ||
import org.hyperledger.besu.plugin.services.PermissioningService; | ||
|
||
import com.google.auto.service.AutoService; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
@AutoService(BesuPlugin.class) | ||
public class TestPermissioningPlugin implements BesuPlugin { | ||
private static final Logger LOG = LogManager.getLogger(); | ||
|
||
private final String aliceNode = | ||
"09b02f8a5fddd222ade4ea4528faefc399623af3f736be3c44f03e2df22fb792f3931a4d9573d333ca74343305762a753388c3422a86d98b713fc91c1ea04842"; | ||
|
||
private final String bobNode = | ||
"af80b90d25145da28c583359beb47b21796b2fe1a23c1511e443e7a64dfdb27d7434c380f0aa4c500e220aa1a9d068514b1ff4d5019e624e7ba1efe82b340a59"; | ||
|
||
private final String charlieNode = | ||
"ce7edc292d7b747fab2f23584bbafaffde5c8ff17cf689969614441e0527b90015ea9fee96aed6d9c0fc2fbe0bd1883dee223b3200246ff1e21976bdbc9a0fc8"; | ||
|
||
@Override | ||
public void register(final BesuContext context) { | ||
PermissioningService service = context.getService(PermissioningService.class).get(); | ||
|
||
service.registerNodePermissioningProvider( | ||
(sourceEnode, destinationEnode) -> { | ||
if (sourceEnode.toString().contains(bobNode) | ||
|| destinationEnode.toString().contains(bobNode)) { | ||
|
||
boolean isBobTalkingToAlice = | ||
sourceEnode.toString().contains(aliceNode) | ||
|| destinationEnode.toString().contains(aliceNode); | ||
if (isBobTalkingToAlice) { | ||
LOG.info("BLOCK CONNECTION from {}, to {}", sourceEnode, destinationEnode); | ||
} else { | ||
LOG.info("ALLOW CONNECTION from {}, to {}", sourceEnode, destinationEnode); | ||
} | ||
|
||
return !isBobTalkingToAlice; | ||
} | ||
return true; | ||
}); | ||
|
||
service.registerNodeMessagePermissioningProvider( | ||
(destinationEnode, code) -> { | ||
if (destinationEnode.toString().contains(charlieNode) && transactionMessage(code)) { | ||
LOG.info("BLOCK MESSAGE to {} code {}", destinationEnode, code); | ||
return false; | ||
} | ||
return true; | ||
}); | ||
} | ||
|
||
private boolean transactionMessage(final int code) { | ||
return code == 0x02 || code == 0x08 || code == 0x09 || code == 0x0a; | ||
} | ||
|
||
@Override | ||
public void start() {} | ||
|
||
@Override | ||
public void stop() {} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.