mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-04-01 00:07:04 +00:00
Compare commits
5 Commits
28.0-dev25
...
28.0-dev29
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5a36a494a | ||
|
|
a54cb917d0 | ||
|
|
30a85a4b92 | ||
|
|
cdbacff996 | ||
|
|
cf127c781c |
@@ -24,7 +24,6 @@
|
|||||||
"redactHeaderContent": "User-Header[REDACTED]",
|
"redactHeaderContent": "User-Header[REDACTED]",
|
||||||
"redactBodyContent": "{ \"User\": \"[REDACTED]\" }",
|
"redactBodyContent": "{ \"User\": \"[REDACTED]\" }",
|
||||||
"regexMaskingBodyContent": "[REDACTED]",
|
"regexMaskingBodyContent": "[REDACTED]",
|
||||||
"minimumEntries": 25,
|
|
||||||
"greenFilterColor": "rgb(210, 250, 210)",
|
"greenFilterColor": "rgb(210, 250, 210)",
|
||||||
"redFilterColor": "rgb(250, 214, 220)",
|
"redFilterColor": "rgb(250, 214, 220)",
|
||||||
"bodyJsonClass": ".hljs",
|
"bodyJsonClass": ".hljs",
|
||||||
|
|||||||
@@ -25,14 +25,16 @@ export function resizeToNormalMizu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function verifyMinimumEntries() {
|
export function verifyMinimumEntries() {
|
||||||
const minimumEntries = Cypress.env('minimumEntries');
|
const entriesSent = Cypress.env('entriesCount');
|
||||||
it(`Making sure that mizu shows at least ${minimumEntries} entries`, async function () {
|
const minimumEntries = Math.round((0.75 * entriesSent));
|
||||||
|
|
||||||
|
it(`Making sure that mizu shows at least ${minimumEntries} entries`, function () {
|
||||||
cy.get('#total-entries').then(number => {
|
cy.get('#total-entries').then(number => {
|
||||||
const getNum = () => {
|
const getNum = () => {
|
||||||
const numOfEntries = number.text();
|
return parseInt(number.text());
|
||||||
return parseInt(numOfEntries);
|
|
||||||
};
|
};
|
||||||
cy.wrap({there: getNum}).invoke('there').should('be.gte', minimumEntries);
|
|
||||||
|
cy.wrap({num: getNum}).invoke('num').should('be.gt', minimumEntries);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import {findLineAndCheck, getExpectedDetailsDict} from "../testHelpers/StatusBarHelper";
|
import {findLineAndCheck, getExpectedDetailsDict} from "../testHelpers/StatusBarHelper";
|
||||||
import {verifyMinimumEntries} from "../testHelpers/TrafficHelper";
|
|
||||||
|
|
||||||
it('check', function () {
|
it('check', function () {
|
||||||
const podName = Cypress.env('name'), namespace = Cypress.env('namespace');
|
const podName = Cypress.env('name'), namespace = Cypress.env('namespace');
|
||||||
@@ -9,8 +8,6 @@ it('check', function () {
|
|||||||
cy.visit(`http://localhost:${port}`);
|
cy.visit(`http://localhost:${port}`);
|
||||||
cy.wait('@statusTap').its('response.statusCode').should('match', /^2\d{2}/);
|
cy.wait('@statusTap').its('response.statusCode').should('match', /^2\d{2}/);
|
||||||
|
|
||||||
verifyMinimumEntries();
|
|
||||||
|
|
||||||
cy.get('.podsCount').trigger('mouseover');
|
cy.get('.podsCount').trigger('mouseover');
|
||||||
findLineAndCheck(getExpectedDetailsDict(podName, namespace));
|
findLineAndCheck(getExpectedDetailsDict(podName, namespace));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,15 +2,12 @@ import {
|
|||||||
checkThatAllEntriesShown,
|
checkThatAllEntriesShown,
|
||||||
isValueExistsInElement,
|
isValueExistsInElement,
|
||||||
resizeToHugeMizu,
|
resizeToHugeMizu,
|
||||||
verifyMinimumEntries
|
|
||||||
} from "../testHelpers/TrafficHelper";
|
} from "../testHelpers/TrafficHelper";
|
||||||
|
|
||||||
it('Loading Mizu', function () {
|
it('Loading Mizu', function () {
|
||||||
cy.visit(Cypress.env('testUrl'));
|
cy.visit(Cypress.env('testUrl'));
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyMinimumEntries();
|
|
||||||
|
|
||||||
checkEntries();
|
checkEntries();
|
||||||
|
|
||||||
function checkEntries() {
|
function checkEntries() {
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import {isValueExistsInElement, verifyMinimumEntries} from '../testHelpers/TrafficHelper';
|
import {isValueExistsInElement} from '../testHelpers/TrafficHelper';
|
||||||
|
|
||||||
it('Loading Mizu', function () {
|
it('Loading Mizu', function () {
|
||||||
cy.visit(Cypress.env('testUrl'));
|
cy.visit(Cypress.env('testUrl'));
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyMinimumEntries();
|
|
||||||
|
|
||||||
isValueExistsInElement(false, Cypress.env('redactHeaderContent'), '#tbody-Headers');
|
isValueExistsInElement(false, Cypress.env('redactHeaderContent'), '#tbody-Headers');
|
||||||
isValueExistsInElement(false, Cypress.env('redactBodyContent'), Cypress.env('bodyJsonClass'));
|
isValueExistsInElement(false, Cypress.env('redactBodyContent'), Cypress.env('bodyJsonClass'));
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import {isValueExistsInElement, verifyMinimumEntries} from '../testHelpers/TrafficHelper';
|
import {isValueExistsInElement} from '../testHelpers/TrafficHelper';
|
||||||
|
|
||||||
it('Loading Mizu', function () {
|
it('Loading Mizu', function () {
|
||||||
cy.visit(Cypress.env('testUrl'));
|
cy.visit(Cypress.env('testUrl'));
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyMinimumEntries();
|
|
||||||
|
|
||||||
isValueExistsInElement(true, Cypress.env('redactHeaderContent'), '#tbody-Headers');
|
isValueExistsInElement(true, Cypress.env('redactHeaderContent'), '#tbody-Headers');
|
||||||
isValueExistsInElement(true, Cypress.env('redactBodyContent'), Cypress.env('bodyJsonClass'));
|
isValueExistsInElement(true, Cypress.env('redactBodyContent'), Cypress.env('bodyJsonClass'));
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import {isValueExistsInElement, verifyMinimumEntries} from "../testHelpers/TrafficHelper";
|
import {isValueExistsInElement} from "../testHelpers/TrafficHelper";
|
||||||
|
|
||||||
it('Loading Mizu', function () {
|
it('Loading Mizu', function () {
|
||||||
cy.visit(Cypress.env('testUrl'));
|
cy.visit(Cypress.env('testUrl'));
|
||||||
});
|
});
|
||||||
|
|
||||||
verifyMinimumEntries();
|
|
||||||
|
|
||||||
isValueExistsInElement(true, Cypress.env('regexMaskingBodyContent'), Cypress.env('bodyJsonClass'));
|
isValueExistsInElement(true, Cypress.env('regexMaskingBodyContent'), Cypress.env('bodyJsonClass'));
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ it('right side sanity test', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
serviceMapCheck();
|
||||||
|
|
||||||
checkIllegalFilter('invalid filter');
|
checkIllegalFilter('invalid filter');
|
||||||
|
|
||||||
checkFilter({
|
checkFilter({
|
||||||
@@ -188,7 +190,7 @@ function checkFilter(filterDetails){
|
|||||||
const entriesForDeeperCheck = 5;
|
const entriesForDeeperCheck = 5;
|
||||||
|
|
||||||
it(`checking the filter: ${name}`, function () {
|
it(`checking the filter: ${name}`, function () {
|
||||||
cy.get('#total-entries').then(number => {
|
cy.get('#total-entries').should('not.have.text', '0').then(number => {
|
||||||
const totalEntries = number.text();
|
const totalEntries = number.text();
|
||||||
|
|
||||||
// checks the hover on the last entry (the only one in DOM at the beginning)
|
// checks the hover on the last entry (the only one in DOM at the beginning)
|
||||||
@@ -320,3 +322,42 @@ function checkOnlyLineNumberes(jsonItems, decodedText) {
|
|||||||
cy.get(`${Cypress.env('bodyJsonClass')} >`).should('have.length', 1).and('have.text', decodedText);
|
cy.get(`${Cypress.env('bodyJsonClass')} >`).should('have.length', 1).and('have.text', decodedText);
|
||||||
cy.get(`${Cypress.env('bodyJsonClass')} > >`).should('have.length', jsonItems)
|
cy.get(`${Cypress.env('bodyJsonClass')} > >`).should('have.length', jsonItems)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function serviceMapCheck() {
|
||||||
|
it('service map test', function () {
|
||||||
|
cy.intercept(`${Cypress.env('testUrl')}/servicemap/get`).as('serviceMapRequest');
|
||||||
|
cy.get('#total-entries').should('not.have.text', '0').then(() => {
|
||||||
|
cy.get('#total-entries').invoke('text').then(entriesNum => {
|
||||||
|
cy.get('[alt="service-map"]').click();
|
||||||
|
cy.wait('@serviceMapRequest').then(({response}) => {
|
||||||
|
const body = response.body;
|
||||||
|
const nodeParams = {
|
||||||
|
destination: 'httpbin.mizu-tests',
|
||||||
|
source: '127.0.0.1'
|
||||||
|
};
|
||||||
|
serviceMapAPICheck(body, parseInt(entriesNum), nodeParams);
|
||||||
|
cy.reload();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function serviceMapAPICheck(body, entriesNum, nodeParams) {
|
||||||
|
const {nodes, edges} = body;
|
||||||
|
|
||||||
|
expect(nodes.length).to.equal(Object.keys(nodeParams).length, `Expected nodes count`);
|
||||||
|
|
||||||
|
expect(edges.some(edge => edge.source.name === nodeParams.source)).to.be.true;
|
||||||
|
expect(edges.some(edge => edge.destination.name === nodeParams.destination)).to.be.true;
|
||||||
|
|
||||||
|
let count = 0;
|
||||||
|
edges.forEach(edge => {
|
||||||
|
count += edge.count;
|
||||||
|
if (edge.destination.name === nodeParams.destination) {
|
||||||
|
expect(edge.source.name).to.equal(nodeParams.source);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(count).to.equal(entriesNum);
|
||||||
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ func TestTap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runCypressTests(t, "npx cypress run --spec \"cypress/integration/tests/UiTest.js\"")
|
runCypressTests(t, fmt.Sprintf("npx cypress run --spec \"cypress/integration/tests/UiTest.js\" --env entriesCount=%d", entriesCount))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/creasty/defaults"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/up9inc/mizu/cli/config/configStructs"
|
||||||
"github.com/up9inc/mizu/cli/telemetry"
|
"github.com/up9inc/mizu/cli/telemetry"
|
||||||
|
"github.com/up9inc/mizu/shared/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var checkCmd = &cobra.Command{
|
var checkCmd = &cobra.Command{
|
||||||
@@ -17,4 +20,11 @@ var checkCmd = &cobra.Command{
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(checkCmd)
|
rootCmd.AddCommand(checkCmd)
|
||||||
|
|
||||||
|
defaultCheckConfig := configStructs.CheckConfig{}
|
||||||
|
if err := defaults.Set(&defaultCheckConfig); err != nil {
|
||||||
|
logger.Log.Debug(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
checkCmd.Flags().Bool(configStructs.PreTapCheckName, defaultCheckConfig.PreTap, "Check pre-tap Mizu installation for potential problems")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/up9inc/mizu/shared"
|
||||||
|
rbac "k8s.io/api/rbac/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/client-go/kubernetes/scheme"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/up9inc/mizu/cli/apiserver"
|
"github.com/up9inc/mizu/cli/apiserver"
|
||||||
@@ -14,7 +18,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func runMizuCheck() {
|
func runMizuCheck() {
|
||||||
logger.Log.Infof("Mizu install checks\n===================")
|
logger.Log.Infof("Mizu checks\n===================")
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel() // cancel will be called when this function exits
|
defer cancel() // cancel will be called when this function exits
|
||||||
@@ -25,17 +29,18 @@ func runMizuCheck() {
|
|||||||
checkPassed = checkKubernetesVersion(kubernetesVersion)
|
checkPassed = checkKubernetesVersion(kubernetesVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
var isInstallCommand bool
|
if config.Config.Check.PreTap {
|
||||||
if checkPassed {
|
if checkPassed {
|
||||||
checkPassed, isInstallCommand = checkMizuMode(ctx, kubernetesProvider)
|
checkPassed = checkK8sTapPermissions(ctx, kubernetesProvider)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if checkPassed {
|
||||||
|
checkPassed = checkK8sResources(ctx, kubernetesProvider)
|
||||||
|
}
|
||||||
|
|
||||||
if checkPassed {
|
if checkPassed {
|
||||||
checkPassed = checkK8sResources(ctx, kubernetesProvider, isInstallCommand)
|
checkPassed = checkServerConnection(kubernetesProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
if checkPassed {
|
|
||||||
checkPassed = checkServerConnection(kubernetesProvider)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if checkPassed {
|
if checkPassed {
|
||||||
@@ -65,27 +70,6 @@ func checkKubernetesApi() (*kubernetes.Provider, *semver.SemVersion, bool) {
|
|||||||
return kubernetesProvider, kubernetesVersion, true
|
return kubernetesProvider, kubernetesVersion, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkMizuMode(ctx context.Context, kubernetesProvider *kubernetes.Provider) (bool, bool) {
|
|
||||||
logger.Log.Infof("\nmode\n--------------------")
|
|
||||||
|
|
||||||
if exist, err := kubernetesProvider.DoesDeploymentExist(ctx, config.Config.MizuResourcesNamespace, kubernetes.ApiServerPodName); err != nil {
|
|
||||||
logger.Log.Errorf("%v can't check mizu command, err: %v", fmt.Sprintf(uiUtils.Red, "✗"), err)
|
|
||||||
return false, false
|
|
||||||
} else if exist {
|
|
||||||
logger.Log.Infof("%v mizu running with install command", fmt.Sprintf(uiUtils.Green, "√"))
|
|
||||||
return true, true
|
|
||||||
} else if exist, err = kubernetesProvider.DoesPodExist(ctx, config.Config.MizuResourcesNamespace, kubernetes.ApiServerPodName); err != nil {
|
|
||||||
logger.Log.Errorf("%v can't check mizu command, err: %v", fmt.Sprintf(uiUtils.Red, "✗"), err)
|
|
||||||
return false, false
|
|
||||||
} else if exist {
|
|
||||||
logger.Log.Infof("%v mizu running with tap command", fmt.Sprintf(uiUtils.Green, "√"))
|
|
||||||
return true, false
|
|
||||||
} else {
|
|
||||||
logger.Log.Infof("%v mizu is not running", fmt.Sprintf(uiUtils.Red, "✗"))
|
|
||||||
return false, false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkKubernetesVersion(kubernetesVersion *semver.SemVersion) bool {
|
func checkKubernetesVersion(kubernetesVersion *semver.SemVersion) bool {
|
||||||
logger.Log.Infof("\nkubernetes-version\n--------------------")
|
logger.Log.Infof("\nkubernetes-version\n--------------------")
|
||||||
|
|
||||||
@@ -169,7 +153,7 @@ func checkPortForward(serverUrl string, kubernetesProvider *kubernetes.Provider)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkK8sResources(ctx context.Context, kubernetesProvider *kubernetes.Provider, isInstallCommand bool) bool {
|
func checkK8sResources(ctx context.Context, kubernetesProvider *kubernetes.Provider) bool {
|
||||||
logger.Log.Infof("\nk8s-components\n--------------------")
|
logger.Log.Infof("\nk8s-components\n--------------------")
|
||||||
|
|
||||||
exist, err := kubernetesProvider.DoesNamespaceExist(ctx, config.Config.MizuResourcesNamespace)
|
exist, err := kubernetesProvider.DoesNamespaceExist(ctx, config.Config.MizuResourcesNamespace)
|
||||||
@@ -198,32 +182,12 @@ func checkK8sResources(ctx context.Context, kubernetesProvider *kubernetes.Provi
|
|||||||
exist, err = kubernetesProvider.DoesServiceExist(ctx, config.Config.MizuResourcesNamespace, kubernetes.ApiServerPodName)
|
exist, err = kubernetesProvider.DoesServiceExist(ctx, config.Config.MizuResourcesNamespace, kubernetes.ApiServerPodName)
|
||||||
allResourcesExist = checkResourceExist(kubernetes.ApiServerPodName, "service", exist, err) && allResourcesExist
|
allResourcesExist = checkResourceExist(kubernetes.ApiServerPodName, "service", exist, err) && allResourcesExist
|
||||||
|
|
||||||
if isInstallCommand {
|
allResourcesExist = checkPodResourcesExist(ctx, kubernetesProvider) && allResourcesExist
|
||||||
allResourcesExist = checkInstallResourcesExist(ctx, kubernetesProvider) && allResourcesExist
|
|
||||||
} else {
|
|
||||||
allResourcesExist = checkTapResourcesExist(ctx, kubernetesProvider) && allResourcesExist
|
|
||||||
}
|
|
||||||
|
|
||||||
return allResourcesExist
|
return allResourcesExist
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkInstallResourcesExist(ctx context.Context, kubernetesProvider *kubernetes.Provider) bool {
|
func checkPodResourcesExist(ctx context.Context, kubernetesProvider *kubernetes.Provider) bool {
|
||||||
exist, err := kubernetesProvider.DoesRoleExist(ctx, config.Config.MizuResourcesNamespace, kubernetes.DaemonRoleName)
|
|
||||||
installResourcesExist := checkResourceExist(kubernetes.DaemonRoleName, "role", exist, err)
|
|
||||||
|
|
||||||
exist, err = kubernetesProvider.DoesRoleBindingExist(ctx, config.Config.MizuResourcesNamespace, kubernetes.DaemonRoleBindingName)
|
|
||||||
installResourcesExist = checkResourceExist(kubernetes.DaemonRoleBindingName, "role binding", exist, err) && installResourcesExist
|
|
||||||
|
|
||||||
exist, err = kubernetesProvider.DoesPersistentVolumeClaimExist(ctx, config.Config.MizuResourcesNamespace, kubernetes.PersistentVolumeClaimName)
|
|
||||||
installResourcesExist = checkResourceExist(kubernetes.PersistentVolumeClaimName, "persistent volume claim", exist, err) && installResourcesExist
|
|
||||||
|
|
||||||
exist, err = kubernetesProvider.DoesDeploymentExist(ctx, config.Config.MizuResourcesNamespace, kubernetes.ApiServerPodName)
|
|
||||||
installResourcesExist = checkResourceExist(kubernetes.ApiServerPodName, "deployment", exist, err) && installResourcesExist
|
|
||||||
|
|
||||||
return installResourcesExist
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkTapResourcesExist(ctx context.Context, kubernetesProvider *kubernetes.Provider) bool {
|
|
||||||
exist, err := kubernetesProvider.DoesPodExist(ctx, config.Config.MizuResourcesNamespace, kubernetes.ApiServerPodName)
|
exist, err := kubernetesProvider.DoesPodExist(ctx, config.Config.MizuResourcesNamespace, kubernetes.ApiServerPodName)
|
||||||
tapResourcesExist := checkResourceExist(kubernetes.ApiServerPodName, "pod", exist, err)
|
tapResourcesExist := checkResourceExist(kubernetes.ApiServerPodName, "pod", exist, err)
|
||||||
|
|
||||||
@@ -273,9 +237,81 @@ func checkResourceExist(resourceName string, resourceType string, exist bool, er
|
|||||||
} else if !exist {
|
} else if !exist {
|
||||||
logger.Log.Errorf("%v '%v' %v doesn't exist", fmt.Sprintf(uiUtils.Red, "✗"), resourceName, resourceType)
|
logger.Log.Errorf("%v '%v' %v doesn't exist", fmt.Sprintf(uiUtils.Red, "✗"), resourceName, resourceType)
|
||||||
return false
|
return false
|
||||||
} else {
|
|
||||||
logger.Log.Infof("%v '%v' %v exists", fmt.Sprintf(uiUtils.Green, "√"), resourceName, resourceType)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Log.Infof("%v '%v' %v exists", fmt.Sprintf(uiUtils.Green, "√"), resourceName, resourceType)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkK8sTapPermissions(ctx context.Context, kubernetesProvider *kubernetes.Provider) bool {
|
||||||
|
logger.Log.Infof("\nkubernetes-permissions\n--------------------")
|
||||||
|
|
||||||
|
var filePath string
|
||||||
|
if config.Config.IsNsRestrictedMode() {
|
||||||
|
filePath = "./examples/roles/permissions-ns-tap.yaml"
|
||||||
|
} else {
|
||||||
|
filePath = "./examples/roles/permissions-all-namespaces-tap.yaml"
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := shared.ReadFromFile(filePath)
|
||||||
|
if err != nil {
|
||||||
|
logger.Log.Errorf("%v error while checking kubernetes permissions, err: %v", fmt.Sprintf(uiUtils.Red, "✗"), err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
obj, err := getDecodedObject(data)
|
||||||
|
if err != nil {
|
||||||
|
logger.Log.Errorf("%v error while checking kubernetes permissions, err: %v", fmt.Sprintf(uiUtils.Red, "✗"), err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var rules []rbac.PolicyRule
|
||||||
|
if config.Config.IsNsRestrictedMode() {
|
||||||
|
rules = obj.(*rbac.Role).Rules
|
||||||
|
} else {
|
||||||
|
rules = obj.(*rbac.ClusterRole).Rules
|
||||||
|
}
|
||||||
|
|
||||||
|
return checkPermissions(ctx, kubernetesProvider, rules)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDecodedObject(data []byte) (runtime.Object, error) {
|
||||||
|
decode := scheme.Codecs.UniversalDeserializer().Decode
|
||||||
|
|
||||||
|
obj, _, err := decode(data, nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkPermissions(ctx context.Context, kubernetesProvider *kubernetes.Provider, rules []rbac.PolicyRule) bool {
|
||||||
|
permissionsExist := true
|
||||||
|
|
||||||
|
for _, rule := range rules {
|
||||||
|
for _, group := range rule.APIGroups {
|
||||||
|
for _, resource := range rule.Resources {
|
||||||
|
for _, verb := range rule.Verbs {
|
||||||
|
exist, err := kubernetesProvider.CanI(ctx, config.Config.MizuResourcesNamespace, resource, verb, group)
|
||||||
|
permissionsExist = checkPermissionExist(group, resource, verb, exist, err) && permissionsExist
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return permissionsExist
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkPermissionExist(group string, resource string, verb string, exist bool, err error) bool {
|
||||||
|
if err != nil {
|
||||||
|
logger.Log.Errorf("%v error checking permission for %v %v in group '%v', err: %v", fmt.Sprintf(uiUtils.Red, "✗"), verb, resource, group, err)
|
||||||
|
return false
|
||||||
|
} else if !exist {
|
||||||
|
logger.Log.Errorf("%v can't %v %v in group '%v'", fmt.Sprintf(uiUtils.Red, "✗"), verb, resource, group)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Log.Infof("%v can %v %v in group '%v'", fmt.Sprintf(uiUtils.Green, "√"), verb, resource, group)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ const (
|
|||||||
|
|
||||||
type ConfigStruct struct {
|
type ConfigStruct struct {
|
||||||
Tap configStructs.TapConfig `yaml:"tap"`
|
Tap configStructs.TapConfig `yaml:"tap"`
|
||||||
|
Check configStructs.CheckConfig `yaml:"check"`
|
||||||
Version configStructs.VersionConfig `yaml:"version"`
|
Version configStructs.VersionConfig `yaml:"version"`
|
||||||
View configStructs.ViewConfig `yaml:"view"`
|
View configStructs.ViewConfig `yaml:"view"`
|
||||||
Logs configStructs.LogsConfig `yaml:"logs"`
|
Logs configStructs.LogsConfig `yaml:"logs"`
|
||||||
|
|||||||
9
cli/config/configStructs/checkConfig.go
Normal file
9
cli/config/configStructs/checkConfig.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package configStructs
|
||||||
|
|
||||||
|
const (
|
||||||
|
PreTapCheckName = "pre-tap"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CheckConfig struct {
|
||||||
|
PreTap bool `yaml:"pre-tap"`
|
||||||
|
}
|
||||||
20
shared/fileUtils.go
Normal file
20
shared/fileUtils.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package shared
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ReadFromFile(path string) ([]byte, error) {
|
||||||
|
reader, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := ioutil.ReadAll(reader)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/up9inc/mizu/shared/semver"
|
"github.com/up9inc/mizu/shared/semver"
|
||||||
"github.com/up9inc/mizu/tap/api"
|
"github.com/up9inc/mizu/tap/api"
|
||||||
v1 "k8s.io/api/apps/v1"
|
v1 "k8s.io/api/apps/v1"
|
||||||
|
auth "k8s.io/api/authorization/v1"
|
||||||
core "k8s.io/api/core/v1"
|
core "k8s.io/api/core/v1"
|
||||||
rbac "k8s.io/api/rbac/v1"
|
rbac "k8s.io/api/rbac/v1"
|
||||||
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
@@ -443,6 +444,26 @@ func (provider *Provider) CreateService(ctx context.Context, namespace string, s
|
|||||||
return provider.clientSet.CoreV1().Services(namespace).Create(ctx, &service, metav1.CreateOptions{})
|
return provider.clientSet.CoreV1().Services(namespace).Create(ctx, &service, metav1.CreateOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (provider *Provider) CanI(ctx context.Context, namespace string, resource string, verb string, group string) (bool, error) {
|
||||||
|
selfSubjectAccessReview := &auth.SelfSubjectAccessReview{
|
||||||
|
Spec: auth.SelfSubjectAccessReviewSpec{
|
||||||
|
ResourceAttributes: &auth.ResourceAttributes{
|
||||||
|
Namespace: namespace,
|
||||||
|
Resource: resource,
|
||||||
|
Verb: verb,
|
||||||
|
Group: group,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err := provider.clientSet.AuthorizationV1().SelfSubjectAccessReviews().Create(ctx, selfSubjectAccessReview, metav1.CreateOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.Status.Allowed, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (provider *Provider) DoesNamespaceExist(ctx context.Context, name string) (bool, error) {
|
func (provider *Provider) DoesNamespaceExist(ctx context.Context, name string) (bool, error) {
|
||||||
namespaceResource, err := provider.clientSet.CoreV1().Namespaces().Get(ctx, name, metav1.GetOptions{})
|
namespaceResource, err := provider.clientSet.CoreV1().Namespaces().Get(ctx, name, metav1.GetOptions{})
|
||||||
return provider.doesResourceExist(namespaceResource, err)
|
return provider.doesResourceExist(namespaceResource, err)
|
||||||
@@ -829,7 +850,7 @@ func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespac
|
|||||||
if tls {
|
if tls {
|
||||||
mizuCmd = append(mizuCmd, "--tls")
|
mizuCmd = append(mizuCmd, "--tls")
|
||||||
}
|
}
|
||||||
|
|
||||||
if serviceMesh || tls {
|
if serviceMesh || tls {
|
||||||
mizuCmd = append(mizuCmd, "--procfs", procfsMountPath)
|
mizuCmd = append(mizuCmd, "--procfs", procfsMountPath)
|
||||||
}
|
}
|
||||||
@@ -939,24 +960,6 @@ func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespac
|
|||||||
sysfsVolumeMount := applyconfcore.VolumeMount().WithName(sysfsVolumeName).WithMountPath(sysfsMountPath).WithReadOnly(true)
|
sysfsVolumeMount := applyconfcore.VolumeMount().WithName(sysfsVolumeName).WithMountPath(sysfsMountPath).WithReadOnly(true)
|
||||||
agentContainer.WithVolumeMounts(sysfsVolumeMount)
|
agentContainer.WithVolumeMounts(sysfsVolumeMount)
|
||||||
|
|
||||||
volumeName := ConfigMapName
|
|
||||||
configMapVolume := applyconfcore.VolumeApplyConfiguration{
|
|
||||||
Name: &volumeName,
|
|
||||||
VolumeSourceApplyConfiguration: applyconfcore.VolumeSourceApplyConfiguration{
|
|
||||||
ConfigMap: &applyconfcore.ConfigMapVolumeSourceApplyConfiguration{
|
|
||||||
LocalObjectReferenceApplyConfiguration: applyconfcore.LocalObjectReferenceApplyConfiguration{
|
|
||||||
Name: &volumeName,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
mountPath := shared.ConfigDirPath
|
|
||||||
configMapVolumeMount := applyconfcore.VolumeMountApplyConfiguration{
|
|
||||||
Name: &volumeName,
|
|
||||||
MountPath: &mountPath,
|
|
||||||
}
|
|
||||||
agentContainer.WithVolumeMounts(&configMapVolumeMount)
|
|
||||||
|
|
||||||
podSpec := applyconfcore.PodSpec()
|
podSpec := applyconfcore.PodSpec()
|
||||||
podSpec.WithHostNetwork(true)
|
podSpec.WithHostNetwork(true)
|
||||||
podSpec.WithDNSPolicy(core.DNSClusterFirstWithHostNet)
|
podSpec.WithDNSPolicy(core.DNSClusterFirstWithHostNet)
|
||||||
@@ -967,7 +970,7 @@ func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespac
|
|||||||
podSpec.WithContainers(agentContainer)
|
podSpec.WithContainers(agentContainer)
|
||||||
podSpec.WithAffinity(affinity)
|
podSpec.WithAffinity(affinity)
|
||||||
podSpec.WithTolerations(noExecuteToleration, noScheduleToleration)
|
podSpec.WithTolerations(noExecuteToleration, noScheduleToleration)
|
||||||
podSpec.WithVolumes(&configMapVolume, procfsVolume, sysfsVolume)
|
podSpec.WithVolumes(procfsVolume, sysfsVolume)
|
||||||
|
|
||||||
podTemplate := applyconfcore.PodTemplateSpec()
|
podTemplate := applyconfcore.PodTemplateSpec()
|
||||||
podTemplate.WithLabels(map[string]string{
|
podTemplate.WithLabels(map[string]string{
|
||||||
@@ -981,7 +984,7 @@ func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespac
|
|||||||
labelSelector.WithMatchLabels(map[string]string{"app": tapperPodName})
|
labelSelector.WithMatchLabels(map[string]string{"app": tapperPodName})
|
||||||
|
|
||||||
applyOptions := metav1.ApplyOptions{
|
applyOptions := metav1.ApplyOptions{
|
||||||
Force: true,
|
Force: true,
|
||||||
FieldManager: fieldManagerName,
|
FieldManager: fieldManagerName,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user