Monday, December 9, 2019

python reserve words

In python some words are reserved to represent some meaning or functionality.
Such types of words are called reserve words.

There are 33 reserved words available in python.

True, False , None 
and, or, not, is 
if, elif, else
while, for, break, continue, return, in, yield 
try, except, finally, raise, assert
import, from, as, class, def, pass, global, nonlocal, lambda, del, with 

Note:

All reserved words in python contain only alphabet symbols.

Except the following 3 reserved words, all contain only lower case alphabet symbols.

True 
False 
None

Eg: a=true ( wrong )  a=True ( right ) 

>>> Import keyword 
>>> keyword.kwlist
[‘False’, ’None’, ’True’, ‘and’, ‘as’, ‘assert’, ‘break’, ‘class’, ‘continue’, ‘def’, ‘del’, ‘elif’, ‘else’, ‘except’, ‘finally’, ‘for’, ‘from’, ‘global’, ‘if’, ‘import’, ‘in’, ‘is’, ‘lambda’, ’nonlocal’, ’not’, ‘or’, ‘pass’, ‘raise’, ‘return’, ’try’, ‘while’, ‘with’, ‘yield’]


Python Identifier

A Name in python program is called identifier.
It can be class name or function name or module name or variable name.

a = 10

Rules to define identifiers in python :  

The  only allowed characters in python are 

  1. Alphabet symbols ( either lower case or upper case )
  2. Digits(0 to 9)
  3. Underscore symbol(_)

By mistake if we are using any other symbol like $ then we will get syntax error.

cash = 10 ( right )
ca$h = 20 ( wrong )

  1. Identifier should not starts with digit 
           123total ( wrong )
            total123 ( right )

     3. Identifiers are case sensitive. Of course python language is case sensitive language.
         total=10
         TOTAL=999
         print(total) #10
         print(TOTAL) #999

Identifier 

Alphabet symbols ( Either upper case or lower case )
If identifier is start with underscore(_) then it indicates it is private.
Identifier should not start with digits
Identifier are case sensitive 
We cannot use reserve words as identifiers ( Eg: def = 10 ( wrong ) )
There is no length limit for the python identifiers. But not recommended to use too lengthy identifiers.
Dollar ( $ ) symbol is not allowed in python.

Which of the following are valid python identifiers ?

123total ( wrong )
total123 ( right )
java2share ( right )
ca$h ( wrong )
_abc_abc_ ( right )
def ( wrong )
if ( wrong ) 

Note:

If identifier starts with _symbol then it indicates that it is private.
If identifier starts with _(Two under score symbols) indicating that strongly private identifier
If the identifier starts and ends with two underscore symbols then the identifier is language defined special name, which is also known as magic methods.


Eg : _add_ 

Sunday, December 8, 2019

Art of SLOs workshop from google. Has theory and practical examples.

https://landing.google.com/sre/resources/practicesandprocesses/art-of-slos/

reference from google.

python

Python is a general purpose high level programming language. Python was developed by Guido Van Rossam in 1989 while working at National Research Institute at Netherlands.

But officially python was made available to public in 1991. The official date of Birth for python o feb 20th 1991.

Python is recommended as first programming language for beginners.

Example : To print hello world 

Java 

  1. public class HelloWorld
  2. {
  3.  p s v main(String[] args)
  4. {
  5.     SOP(“Hello world”);
  6.  }
  7. }

C:

#include <stdio.h>
void main()
{
   print(“Hello world”);
}

Python:

print(“Hello World”)

Eg: To print the sum of 2 numbers 

Java: 

public class Add
{
    public static void main(String[] args)
    {
         int a,b;
         a =10;
         b =20;
         System.out.println(“The Sum:” +(a+b));
          }
  }

C:

#include <stdio.h>
void main()
{

    int a,b;
    a =10;
    b =20;
    printf(“The Sum:%d”,(a+b));
 
}

Python:

a=10;
b=20;
Print(“The Sum:”,(a+b))

The name python was selected from the TV show
“The complete Monty python’s Circus”, which was broadcasted in BBC from 1969 to 1974.

Guido developed python language by taking almost all programming features from different languages.

Functional programming features from C
Object oriented programming features from C++
Scripting language features from perl and shell script 
Modular programming features from Modula-3 

Most of syntax is python derived from C and ABC languages.

In usage

Common application areas are :

Developing desktop applications 
Developing web applications 
Developing database applications 
Network programming 
Developing games 
Data analysis applications 
Machine learning 
Developing artificial intelligence applications 
IOT 

Features of Python:

  1. Simple and easy to learn : python is a simple programming language. When we read python program, we can feel like reading English statements. The syntaxes are very simple and only 30 + keywords are available. When compared with other languages, we can write programs with very less number of lines. Hence more readability and simplicity. We can reduce development and cost of the project.
    
      2. Freeware and open source : we can use python software without any license and it is freeware. Its source code is open, so that we can customize based on your requirements. ( example : Jython is customized version of python to work with java application.

      3. High level programming language : python is high level programming language and hence it is programmer friendly language. Being a programmer  we are not required to concentrate low level activities like memory management and security etc.

     4. Platform independent : once we write a python program, it can run on any platform without rewriting once again. Internally PVM is responsible to convert into machine understandable form.

     5. Portability :  python programs are portable. Ie we can migrate from one platform to another platform very easily. Python programs will provide same results on any platform.

     6. Dynamically typed : In python we are not required to declare type for variables. Whenever we are assigning the value, based on value, type will be allocated automatically. Hence python is considered as dynamically typed language. But Java, C etc are statically typed language b’z we have to provide type at the beginning only.
  1.  Both procedure oriented and object oriented: python language supports both procedure oriented  ( like C, pascal etc ) and object oriented ( like C++, java ) features. Hence we can get benefits of both like security and reusability etc.

      8. Interpreted : we are not required to compile python programs explicitly. Internally python interpreter will take care that compilation. If compilation fails interpreter raised syntax errors. Once complilation success then PVM ( python virtual machine ) is responsible to execute.
 
     9. Extensible : we can use other languages programs in python. The main advantages of this approach are: we can use already existing legacy non-python code. We can improve performance of the application.

     10. Embedded : we can use python programs in any other languages programs. We can embedd python programs anywhere.

      11. Extensive library : python has a rich inbuilt library. Being a programmer we can use this library directly and we are not responsible to implement the functionality etc 

Limitations of python : 
Performance wise not up to mark because it is intrepreted language. Not using for mobile applications.

Flavours of python : 

  1. CPython : it is the standard flavor of python. It can be used to work with C language applications.
  2. Jython or JPython : it is for Java applications. It can run on JVM 
  3. IronPython : it is for C#.Net platform 
  4. PyPy : The main advantage of PyPy is performance will be improved because JIT compiler is available inside PVM.
  5. RubyPython : For Ruby platforms.
  6. Anaconda python : it is specially designed for handling large volume of data processing.

Python versions : 
Python 1.0 v introduced in jan 1994
Python 2.0 v introduced in October 2000
Python 3.0v introduced in December 2008

Note : python 3 won’t provide backward compatibility to python2 i.e there is no guarantee that python2 programs will run in python3.


Saturday, December 7, 2019

what is CWE ?

Fullform of CWE is Common Weakness enumeration 

The Common Weakness Enumeration (CWE™) Top 25 Most Dangerous Software Errors (CWE Top 25) is a demonstrative list of the most widespread and critical weaknesses that can lead to serious vulnerabilities in software. These weaknesses are often easy to find and exploit. They are dangerous because they will frequently allow adversaries to completely take over execution of software, steal data, or prevent the software from working. The CWE Top 25 is a community resource that can be used by software developers, software testers, software customers, software project managers, security researchers, and educators to provide insight into some of the most prevalent security threats in the software industry.
To create the list, the CWE Team used a data-driven approach that leverages published Common Vulnerabilities and Exposures (CVE®) data and related CWE mappings found within the National Institute of Standards and Technology (NIST) National Vulnerability Database (NVD), as well as the Common Vulnerability Scoring System (CVSS) scores associated with each of the CVEs. A scoring formula was then applied to determine the level of prevalence and danger each weakness presents. This data-driven approach can be used as a repeatable, scripted process to generate a CWE Top 25 list on a regular basis with minimal effort.


reference:

Top 25 is list here :


reference:

one-way hash :  A one-way hash maps data of arbitrary size to a bit-string of fixed size ( the hash value ) such that the process is infeasible to invert. Used in cryptographic functions, such as strong passwords securely

salt : A salt is randow data that is used as an additional input to a one-way function that hashes a password or passpharse. it ensures the randomness of the hashed outcome, making the hash very difficult to crack.

brute-force attacks : In a brute-force attacks, the attacker iteratively tries hashing all possible values and compares the hashes to the stored hashes.
( if weak hashing is used, even strong passwords can be easily compromised by brute-force attacks).
[ In practice, even when strong hashing is used, hashed passwords might be vulnerable to dictionary attacks ].

what is dictionary attacks ?
In a dictionary attacks, the attacker hashes a list ( dictionary ) of possible passwords and compares them to stored hashes.

How to prevent weak hashing ?

Generate a random salt

[ each time you process a new password. Add the salt to the plaintext password before hashing it. When you store the hash, also store the salt ]

suggestion:
Do not use the same salt for every password that you process (CWE-760).

Use one-way hashing

[  that allow you to configure many rounds, such as bcrypt. This may increase the expense when processing incoming authentication requests, but if the hashed passwords are ever stolen, it significantly increases the effort for conducting a brute force attack, including rainbow tables

Testing [ How to test the weak hashing vulnerabilities ? ]

Find the hashes used by the application.
Determine the algorithm used for hashing.
Decide whether the hashing algorithm matches application security requirements:
Make sure that an iterative hashing algorithm with a sufficient number of rounds is used.
Make sure that a unique salt is used for each password and is stored with the hash.
Not using a salt, not using an iterative algorithm, or not using a sufficiently large amount of round all constitute weaknesses of this type.














Friday, October 4, 2019

how to setup spinnaker and jenkins using the helm provider

Step1 : 
•Login for Azure account :   az login

Step2:  To the set the account to the specific subscription \
az account set -s   ******************

Step3: To get the kubeconfig
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster

Step4: Open the K8s dashboard using AZ-CLI
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster

•Open the K8s dashboard using AZ-CLI
        az aks browse --resource-group demo_cluster --name demo-cluster

Step5: •Create clusterrolebinding to give access to kubernetes-dashboard(ServiceAccount) for your respective namespaces
Kubectl create clusterrolebinding view-dashboard  —clusterrole=cluster-admin  —serviceaccount=kube-system:kubernetes-dashboard

Step6:
kubectl create clusterrolebinding add-on-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:default
   a.    Create ServiceAccnt & Clusterolebinding with Cluster-admin access the serviceaccnt
   apiVersion: v1
kind: ServiceAccount
metadata:
  name: tiller
  namespace: kube-system
---
kind: ClusterRoleBinding
metadata:
  name: tiller
roleRef:
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: tiller
    namespace: kube-system

Step7:  helm install & init 
•helm init
Install Tiller --> helm init --service-account tiller

Extras :

Create a spinnaker :
Why this helm init --upgrade --service-account tiller ?
Error: release default failed: namespaces "default" is forbidden: User "system:serviceaccount:kube-system:default" cannot get resource "namespaces" in API group "" in the namespace "default"
That is why we need to upgrade it.
helm install stable/spinnaker --name spinnaker-demo -n default

Step8: 
•Install Traefik in Jenkins Namespace
               helm install stable/traefik --name traefik --set dashboard.enabled=true,serviceType=LoadBalancer,dashboard.domain=example-jenkinsinstance.eastus.***********.com,rbac.enabled=true  --namespace jenkins
•Once the FrontEndIP is created under Loadbalancers for Traefik in Azure portal, then create a DNS Label(same as which was specified in  the above command) for this FrontEndIP.

Step9:
•Create namespace called  Spinnaker and Install Spinnaker using Helm

      helm install --name spinnaker stable/spinnaker --timeout 600 --namespace=spinnaker

How to create the Dockerfile for Jsonnet

We can use this in the windows operating system.



FROM bitnami/jsonnet:latest

COPY ./demo /var
WORKDIR /var/demo/

ENTRYPOINT [ "jsonnet", "/demo-app-gce.jsonnet" ]

The Directory used in the Dockerfile  ( 

reference repo : https://github.com/spinnaker/spinnaker/tree/master/sponnet/demo

).

run this command to test the jsonnet file:

docker run -it --rm jsonnet-image